iphone - 为什么我无法在我的 iOS 应用程序中对 Facebook Chat 进行身份验证?

标签 iphone ios objective-c facebook

我一直在网上搜索,试图找到解决这个问题的方法。我了解它应该如何工作的基本思想,但我无法让实现工作,也找不到任何像样的例子来帮助我。到目前为止,我已经能够使用 iOS 6 身份验证机制成功登录用户,但我不知道如何从那里向 Jabber 服务器验证用户身份。这是我所拥有的:

用户登录后调用connect

-(void)connect
{
    [self setupStream];
    NSError *error = nil;
    [_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
    NSLog(@"%@", error);
    [NSString stringWithFormat:@"%@", self];
}

-(void)newSetupStream
{
    _xmppStream = [[XMPPStream alloc] initWithFacebookAppId:@"611051652253156"];

#if !TARGET_IPHONE_SIMULATOR
{
    xmppStream.enableBackgroundingOnSocket = YES;
}
#endif


    _xmppReconnect = [[XMPPReconnect alloc] init];


    _xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init];

    _xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:_xmppRosterStorage];
    _xmppRoster.autoFetchRoster = YES;
    _xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = YES;


    _xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
    _xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:_xmppvCardStorage];
    _xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:_xmppvCardTempModule];


    _xmppCapabilitiesStorage = [XMPPCapabilitiesCoreDataStorage sharedInstance];
    _xmppCapabilities = [[XMPPCapabilities alloc] initWithCapabilitiesStorage:_xmppCapabilitiesStorage];
    _xmppCapabilities.autoFetchHashedCapabilities = YES;
    _xmppCapabilities.autoFetchNonHashedCapabilities = NO;


    [_xmppReconnect         activate:_xmppStream];
    [_xmppRoster            activate:_xmppStream];
    [_xmppvCardTempModule   activate:_xmppStream];
    [_xmppvCardAvatarModule activate:_xmppStream];
    [_xmppCapabilities      activate:_xmppStream];


    [_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [_xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()];
}

无论我尝试什么,它总是返回相同的错误:Error Domain=XMPPStreamErrorDomain Code=4 "The server does not support X-FACEBOOK-PLATFORM authentication."

我对 XMPP 或 Facebook API 都不太熟悉,所以我确定我缺少一些简单的东西,但我一直在努力解决这个问题,但无法取得任何进展。有什么想法吗?

最佳答案

我找到了答案。以防其他人遇到同样的问题:我实际上从未告诉我的 XMPPStream 进行连接。我之前尝试过所有连接方法,但它们从未奏效。我现在意识到我根本没有等到他们完成连接。这是我最终更改的内容:

NSError *error;
NSError *err;
[_xmppStream connectWithTimeout:10.00 error:&err];

[_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
while (error)
{
    sleep(1);
    [_xmppStream authenticateWithFacebookAccessToken: FBSession.activeSession.accessTokenData.accessToken error:&error];
}

我意识到这不是最优雅的解决方案,但它确实有效。

关于iphone - 为什么我无法在我的 iOS 应用程序中对 Facebook Chat 进行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17123425/

相关文章:

objective-c - 如何调用 Objective C 函数?

iphone - 使用 NSOperationQueue 作为 View Controller 实例变量

iphone - 如何找到NSString使用的内存?

.net - 将图像从 iPhone 上传到 .net ashx 处理程序

ios - ionic Cordova 使用媒体插件在 IOS 上录制音频失败

ios - 次调用方法-iOS

ios - NEVPNManager 实例显示为 nil

iphone - 如何检查您的 iPhone 联系人列表中的人是否安装了应用程序?

ios - 将 RealmSearchViewController 与 UITableView 结合使用

ios - 仅本地图靠近屏幕边缘时,如何才能将 map 置于注释 View 的中心?