3

我正在尝试创建一个实现 Facebook 聊天的应用程序。据我所知,我已经正确设置了所有 XMPP 东西,但我无法让它工作。

用户登录并通过 Facebook 身份验证后(通过FBSession),我尝试连接到聊天服务。这是 XMPP 的用武之地:

-(void)connect
{
    [self setupStream];
    NSError *err;

    [self.xmppStream connectWithTimeout:10.00 error:&err];
}

-(void)setupStream
{
    _xmppStream = [[XMPPStream alloc] initWithFacebookAppId:FACEBOOK_APP_ID];
    [self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
}

- (void)xmppStreamDidConnect:(XMPPStream *)sender {
    NSError *error;
    NSError *err;
    [self.xmppStream secureConnection:&err];
    bool authed = [self.xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
    NSLog(@"%@", err);
    NSLog(@"%@", [self.xmppStream authenticationDate]);
    NSLog(@"%d, %@", authed, error);
}

- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender {
    NSLog(@"did authenticate");
    [self goOnline];
}

运行上述程序时,一切似乎都很好:xmppStreamDidConnect在短暂等待后调用并authed始终返回 YES 并且其错误始终为null.

但是,secureConnection返回Error Domain=XMPPStreamErrorDomain Code=1“请等待,直到流连接。” UserInfo=0xb23dc30 {NSLocalizedDescription=请等待,直到流连接。}authenticationDate总是null如此。此外,从未调用过任何其他委托方法,包括xmppStreamDidAuthenticate. 我究竟做错了什么?

4

1 回答 1

3

我终于找到答案了!!在这里,以防其他人遇到与我相同的问题:

当调用对象实际上并不与 Facebook 服务器通信或尝试对其进行身份验证时,它只是加载先前的 authenticationToken openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:FBSession就我而言,这个令牌已经失效,但我没有意识到,也没有什么可以告诉我的。我终于通过记录令牌并将其放入 Facebook 的Access Token Debugger来解决这个问题。要检查您的令牌是否有效,您必须调用[FBSession renewSystemCredentials:]并等待结果。closeAndClearTokenInformation然后,您可以在尝试创建新令牌之前确定是否需要手动操作。

于 2013-06-23T11:26:04.847 回答