接着上面说
用户注册是比较简单的,成功连接上服务器后,设置好JID,即可调用
[_xmppStream registerWithPassword:pwd error:&err]
进行注册
-(BOOL)registerUser:(NSString*)user withpassword:(NSString*)pwd { user = [NSString stringWithFormat:@"%@@%@",user,_xmppStream.hostName]; if (![_xmppStream isConnected]) { [self connect:user withpassword:nil]; } [_xmppStream setMyJID:[XMPPJID jidWithString:user resource:@"ios"]]; NSError *err; if([_xmppStream registerWithPassword:pwd error:&err]) {return YES;} else{return NO;} }
注册结果返回
///注册成功 - (void)xmppStreamDidRegister:(XMPPStream *)sender { [[NSUserDefaults standardUserDefaults] setObject:sender.myJID.user forKey:kXMPPmyJID]; [_mainController setuserLabel:sender.myJID.user]; [_navigateionController popToRootViewControllerAnimated:YES]; [_mainController setRegisterResult:YES]; NSLog(@"账户注册成功"); [self goOnline]; } ///注册失败 - (void)xmppStream:(XMPPStream *)sender didNotRegister:(NSXMLElement *)error { [_mainController setRegisterResult:NO]; NSLog(@"账户注册失败"); NSLog(@"%@",error); }