3

我安装了 XMPP,它用于在我的 iOS 应用程序中聊天。用户应该可以注销并让其他用户登录并使用该应用程序。目前 XMPP 聊天运行良好,但如果我注销并尝试使用不同的用户名再次登录,则会出现以下错误。

2012-11-22 14:15:52.520 FMB[3297:c07] *** Assertion failure in -[AppDelegate setupStream], /Visni/Project/FMBXMPP/FMB/AppDelegate.m:843
2012-11-22 14:15:52.541 FMB[3297:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Method setupStream invoked multiple times'
*** First throw call stack:
(0x24ee012 0x1fe3e7e 0x24ede78 0x1a79f35 0x6b46 0x8f49 0x50938 0x2f4a3 0x2ea84 0x215653f 0x2168014 0x21587d5 0x2494af5 0x2493f44 0x2493e1b 0x2b1b7e3 0x2b1b668 0xf2b65c 0x288a 0x2795)
libc++abi.dylib: terminate called throwing an exception

我的注销方法中有以下代码。

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        [appDelegate disconnect];

关于如何正确注销用户并准备新登录的任何想法?

4

2 回答 2

2

您可以通过以下方式断开 XMPP:

- (void) disconnectXMPP
{
    [self.xmppStream removeDelegate:self];
    [xmppReconnect         deactivate];
    [self.xmppStream disconnect];
    self.xmppStream = nil;
}
于 2014-09-25T07:57:40.940 回答
1

我不知道我所做的是否是最好的方法,但它确实有效。

注销我使用

- (void)resetField:(NSString *)field forKey:(NSString *)key
{

    [[NSUserDefaults standardUserDefaults] setObject:field forKey:key];

}

- (IBAction)logout:(id)sender {

[self resetField:@"" forKey:kXMPPmyJID];
[self resetField:@"" forKey:kXMPPmyPassword];

[[[self appDelegate] xmppStream ]disconnect];
[[[self appDelegate] xmppvCardTempModule] removeDelegate:self];



}

然后再次登录:

 - (void)setField:(UITextField *)field forKey:(NSString *)key {
if (field.text != nil)
{
    [[NSUserDefaults standardUserDefaults] setObject:field.text forKey:key];
} else {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
} 
 }

- (IBAction)login:(id)sender {

[self setField:jidField forKey:kXMPPmyJID];
[self setField:passwordField forKey:kXMPPmyPassword];
[[self appDelegate] connect];  
}

希望能帮助到你!

于 2013-10-28T13:30:24.967 回答