接着上面說ios
用戶註冊是比較簡單的,成功鏈接上服務器後,設置好JID,便可調用服務器
[_xmppStream registerWithPassword:pwd error:&err]
進行註冊spa
-(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;} }
註冊結果返回code
///註冊成功 - (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); }