无法从目标 c 中的 ejabbered xmpp 注册新用户
Posted
技术标签:
【中文标题】无法从目标 c 中的 ejabbered xmpp 注册新用户【英文标题】:unable to register new user from ejabbered xmpp in objective c 【发布时间】:2015-05-25 05:34:16 【问题描述】:在 SignupViewController 中
if (![[[self appdelegate] xmppStream] isConnected])
[[self appdelegate] setupStream];
[[self appdelegate]connect] && [[self appdelegate].xmppStream supportsInBandRegistration];
else
[[self appdelegate] registerWithElements];
在 AppDelegate.m 中
- (void)registerWithElements
NSError *error = nil;
NSMutableArray *elements = [NSMutableArray array];
[elements addObject:[NSXMLElement elementWithName:@"username" stringValue:[UserDefaultsManager getUsername]]];
[elements addObject:[NSXMLElement elementWithName:@"password" stringValue:[UserDefaultsManager getPassword]]];
[elements addObject:[NSXMLElement elementWithName:@"email" stringValue:[UserDefaultsManager getUsername]]];
[[self xmppStream] registerWithElements:elements error:&error];
它总是在 didNotRegister 方法中。请提供合适的解决方案以成功注册。
【问题讨论】:
【参考方案1】:希望对您有所帮助:
- (AppDelegate *)appDelegate
return (AppDelegate *)[[UIApplication sharedApplication]delegate];
- (XMPPStream *)xmppStream
return [[self appDelegate] xmppStream];
-(void)registerUser
NSString *myJID = userName;
NSString *myPassword = password;
//
// If you don't want to use the Settings view to set the JID,
// uncomment the section below to hard code a JID and password.
//
// myJID = @"raj@h.local";
// myPassword = @"123";
//if (myJID == nil || myPassword == nil)
// return ;
//
[_xmppStreamM setMyJID:[XMPPJID jidWithString:myJID]];
//password = myPassword;
NSError *error = nil;
if (![_xmppStreamM connectWithTimeout:XMPPStreamTimeoutNone error:&error])
if (myJID == nil || myPassword == nil)
return ;;
[_xmppStreamM setMyJID:[XMPPJID jidWithString:myJID]];
//_password = myPassword;
//NSError *error = nil;
if (![_xmppStreamM connectWithTimeout:XMPPStreamTimeoutNone error:&error])
[[[self appDelegate] xmppStream] connectWithTimeout:XMPPStreamTimeoutNone error:nil];
//_userName = self.userName.text;
// NSString *password = self.password.text;
// NSString *name =@"raj";
//
//
// NSString *email=@"raj@gmail.com";
NSMutableArray *elements = [NSMutableArray array];
[elements addObject:[NSXMLElement elementWithName:@"username" stringValue:@"username"]];
[elements addObject:[NSXMLElement elementWithName:@"password" stringValue:@"password"]];
[[[self appDelegate] xmppStream] registerWithElements:elements error:nil];
NSLog(@"Register ====%@",[[self appDelegate] xmppStream]);
NSLog(@"Register ====%@",elements);
【讨论】:
没有。我已经通过从应用程序委托调用它来完成上述相同的事情。所以你能解释一下为什么我需要写这个吗? 我总是面临这个问题错误:-以上是关于无法从目标 c 中的 ejabbered xmpp 注册新用户的主要内容,如果未能解决你的问题,请参考以下文章
如何在目标c中通过ios中的XMPPFramework连接XMPP服务器