gpt4 book ai didi

ios - 如何在iOS的XMPPFrameWork中创建新的用户帐户

转载 作者:行者123 更新时间:2023-12-01 16:44:54 27 4
gpt4 key购买 nike

嗨,我已经尝试过使用IOS中的XMPPFrameWork进行新用户注册的一些代码。

    -(IBAction)Registaton:(id)sender
{
// iPhoneXMPPAppDelegate *appDelegate =(iPhoneXMPPAppDelegate *)[[UIApplication sharedApplication]delegate];

[[[self appDelegate] xmppStream] connectWithTimeout:XMPPStreamTimeoutNone error:nil];
NSString *username = self.username.text;
NSString *password = self.password.text;
NSString *name =self.name.text;
NSString *email=self.email.text;

NSMutableArray *elements = [NSMutableArray array];
[elements addObject:[NSXMLElement elementWithName:@"username" stringValue:username]];
[elements addObject:[NSXMLElement elementWithName:@"password" stringValue:password]];
[elements addObject:[NSXMLElement elementWithName:@"name" stringValue:name]];

[elements addObject:[NSXMLElement elementWithName:@"email" stringValue:email]];

[[[self appDelegate] xmppStream] registerWithElements:elements error:nil];
NSLog(@"Register ====%@",[[self appDelegate] xmppStream]);

//[[[self appDelegate] xmppStream] registerWithPassword:elements error:nil];

}

但是通过这种方法我无法在服务器上注册。它使我可以连接到Xmppstream。请稍候。任何人都可以帮助我如何在ios中使用XMPPFrameWork在服务器上创建新帐户。

最佳答案

试试这个。它对我来说很好

- (void)updateAccountInfo
{


//NSString *domain = [[NSString alloc] initWithString:@"192.168.1.100"];

//int port = 5222;
NSString *usname =[[NSString alloc] initWithString:self.txtUsername.text];
NSString *juser =[[NSString alloc] initWithString:[usname stringByAppendingString:@"your server ip"]];

XMPPJID *jid = [XMPPJID jidWithString:juser];
[self xmppStream].myJID =jid;

allowSelfSignedCertificates = NSOnState;
allowSSLHostNameMismatch = NSOnState;
NSUserDefaults *dflts = [NSUserDefaults standardUserDefaults];

//[dflts setObject:domain forKey:@"Account.Server"];

// [dflts setObject:(port ? [NSNumber numberWithInt:port] : nil)
// forKey:@"Account.Port"];

[dflts setObject:juser
forKey:@"Account.JID"];
[dflts setObject:@"ios"
forKey:@"Account.Resource"];

[dflts setBool:useSSL forKey:@"Account.UseSSL"];
[dflts setBool:allowSelfSignedCertificates forKey:@"Account.AllowSelfSignedCert"];
[dflts setBool:allowSSLHostNameMismatch forKey:@"Account.AllowSSLHostNameMismatch"];
[dflts setBool:YES forKey:@"Account.RememberPassword"];

[dflts setObject:self.txtPasswd.text forKey:@"Account.Password"];
[dflts synchronize];



}

- (void)createAccount
{
[self updateAccountInfo];

NSError *error = nil;
BOOL success;

if(![[[self appDelegate] xmppStream] isConnected])
{

if (useSSL)
success = [[self xmppStream] oldSchoolSecureConnectWithTimeout:XMPPStreamTimeoutNone error:&error];
else
success = [[self xmppStream] connectWithTimeout:XMPPStreamTimeoutNone error:&error];
}
else
{
//NSString *password = [[NSString alloc] initWithString:@"321" ];

success = [[self xmppStream] registerWithPassword:self.txtPasswd.text error:&error];
}

if (success)
{
[self appDelegate].isRegistering = YES;
}
else
{
NSLog(@"not succeed ");

}
}
- (void)xmppStreamDidRegister:(XMPPStream *)sender{


UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Registration" message:@"Registration with XMPP Successful!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];

}



- (void)xmppStream:(XMPPStream *)sender didNotRegister:(NSXMLElement *)error{

DDXMLElement *errorXML = [error elementForName:@"error"];
NSString *errorCode = [[errorXML attributeForName:@"code"] stringValue];

NSString *regError = [NSString stringWithFormat:@"ERROR :- %@",error.description];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Registration with XMPP Failed!" message:regError delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

if([errorCode isEqualToString:@"409"]){

[alert setMessage:@"Username Already Exists!"];
}
[alert show];
}

关于ios - 如何在iOS的XMPPFrameWork中创建新的用户帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20783710/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com