【问题标题】:iOS XMPP Framework XMPPStream Not Connecting?iOS XMPP 框架 XMPPStream 未连接?
【发布时间】:2014-09-22 21:27:39
【问题描述】:

我正在尝试使用 iOS 上的 XMPPFramework 连接到公共 XMPP 服务器。我在应用加载时设置了连接

- (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];

连接中:

- (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]);
}

然后是我的委托方法:

- (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。有什么想法吗?

【问题讨论】:

  • 我尝试了您的代码,无论我做什么,我似乎都没有收到任何错误。它对我不起作用。
  • 这是我遇到的问题,这该死的东西根本不会说话。

标签: ios objective-c xmpp xmppframework


【解决方案1】:

我通过更改来修复它:

 NSString *username = @"eric1234@jabber.web.id";

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-02-26
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 2014-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多