关于objective C:iOS XMPP 框架 XMPPStream 未连接?

iOS XMPP Framework XMPPStream Not Connecting?

我正在尝试使用 iOS 上的 XMPPFramework 连接到公共 XMPP 服务器。当应用程序加载到

中时,我设置了连接

1
2
3
4
5
6
7
8
9
10
11
12
13
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    // Set up XMPP stream

    self.xmppStream = [[XMPPStream alloc] init];
    [self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];

    self.xmppStream.hostName = @"jabber.web.id";
    self.xmppStream.hostPort = 5222;

    [self connect];

连接中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- (void)connect {
    NSString *username = @"eric1234";
    self.password = @"test123";

    [self.xmppStream setMyJID:[XMPPJID jidWithString:username]];

    NSError *error = nil;
    if (![self.xmppStream oldSchoolSecureConnectWithTimeout:XMPPStreamTimeoutNone error:&error])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                            message:[NSString stringWithFormat:@"Can't connect to server %@", [error localizedDescription]]
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
        [alertView show];
    }

    NSLog(@"%hhd", [self.xmppStream isConnected]);
}

然后是我的委托方法:

1
2
3
4
5
6
7
8
9
10
11
12
- (void)xmppStreamDidConnect:(XMPPStream *)sender {
    NSError *error = nil;
    if (![self.xmppStream authenticateWithPassword:self.password error:&error]) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                            message:[NSString stringWithFormat:@"Can't authenticate %@", [error localizedDescription]]
                                                           delegate:nil
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
        [alertView show];
    }
    [self.xmppStream sendElement:[XMPPPresence presence]];
}

xmppStreamDidConnect 永远不会被调用。我不知道为什么,我已经使用服务器上的桌面 XMPP 客户端在 jabber.web.id 上成功注册了 eric1234。有什么想法吗?


9创建正确的JID:
所以,在上面的概率。

1
NSString *username = @"eric1234@domain_name";     (domain name may be diff. than hostname.)

我通过更改来修复它:

1
 NSString *username = @"[email protected]";