将用户的Facebook凭证导入iOS6 [英] Importing user's Facebook credentials into iOS6

查看:84
本文介绍了将用户的Facebook凭证导入iOS6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新版Facebook SDK 3.0的文档告诉我们:

The documentation for the new Facebook SDK 3.0 tells us this:

"在某些情况下,iOS设备将没有已将应用程序连接到其Facebook帐户的用户的访问令牌.当用户使用某个应用程序的网站或在另一台移动设备上使用该应用程序时,可能会发生这种情况要使用iOS 6本机身份验证对话框",应用程序需要将用户的凭据导入"到设备中,并需要显示iOS 6本机身份验证对话框"."

"In some cases, the iOS device won't have an access token for a user who has already connected an app to their Facebook account. This can happen when a user used an app's website or used the app on another mobile device. To use the iOS 6 native Auth Dialog, apps need to 'import' the user's credentials into the device and need to show the iOS 6 native Auth Dialog."

(请参见 http://developers.facebook.com/docs/howtos/ios -6/,技巧2)

我想知道如何导入此数据,我找不到代码示例.

I'd like to know how to import this data, I can't find a code example.

谢谢

蒂姆

P.S.为了提供信息(以及进行测试),可以在应用中轻松重现上述情况:

P.S. For information (and testing purposes) it's easy to reproduce the above situation in an app:

  1. 在设置应用中,删除Facebook帐户
  2. 正在开发的应用程序通过SSO连接到Facebook,(鉴于没有在iOS6下注册的Facebook帐户,因此应回到此状态
  3. 在设置应用中再次设置Facebook帐户
  4. 再次尝试通过开发中的应用登录.由于令牌是使用令牌创建的,因此这次它将通过SSO still 继续访问Facebook.
  1. In the settings app, delete the Facebook account
  2. In the app under development connect to Facebook via SSO, (it should fall back to this given that there's no Facebook account registered under iOS6
  3. Set up the Facebook account again in the settings app
  4. Once again, try signing in via the app under developement. This time it will still access Facebook via SSO since the token was created using it.

推荐答案

正如MrNickBarker所建议的那样,解决方案是使用户退出SSO.但是,只有在绝对确定这样做时,他们才想通过iOS 6身份验证系统重新登录他们的用户.

As MrNickBarker suggested the solution is to log the user out of SSO. However, I only wanted to do this if I was absolutely sure that in doing so they user would be logged back in via the iOS 6 authentication system.

我的问题是我不知道一种确保用户通过设置"应用程序登录到Facebook的方法,并且我不想让用户退出Facebook,只是想让他们发送回Facebook每次都有用于SSO登录的Facebook应用.

My problem was that I didn't know of a way of ensuring that the user was logged into Facebook via the Settings app, and I didn't want to log the user out of Facebook only to have them send back to the Facebook app for an SSO login each and every time.

如果我最终发现[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]确实做到了这一点,那么ACAccountStore方法都不会告诉您用户是否已在设置"应用中输入了他们的Facebook详细信息.

None of the ACAccountStore methods will tell you if the user has entered their Facebook details into the Settings app, hwoever I finally discovered [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] which does exactly this.

然后是解决方法:

ACAccountStore *accountStore = [[NSClassFromString(@"ACAccountStore") alloc] init];
ACAccountType *accountType;
if (accountStore &&
    (accountType = [accountStore accountTypeWithAccountTypeIdentifier:@"com.apple.facebook"]) &&
    [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
    // There's an account store and it knows about Facebook - we must be on iOS 6 or higher.
    //
    // [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] also tells us that
    // the user has signed into their Faecbook account via the Settings app.
    //
    // At this point there could be a valid session that's been previously created via SSO prior to the
    // user signing into Facebook from Settings.app. In this case, calling openActiveSessionWithReadPermissions:
    // will continue to log on using SSO rather than the preferred route of using the built in iOS support.
    //
    // [accountStore accountsWithAccountType:accountType] will return an account for this application once
    // it's been used to log into Facebook. Clearly, if there is an account returned then the then we don't want to
    // force a logout.
    //
    // On the other hand, if no accounts are returned then we can safely call closeAndClearTokenInformation
    // in order to clear any SSO tokens, thereby ensuring that the next login will attempt to use the iOS
    // authentication (which we can do since the user has signed into the Settings app).

    if ([[accountStore accountsWithAccountType:accountType] count] == 0)
        [FBSession.activeSession closeAndClearTokenInformation];

    // Try to connect with read permissions only (as required for iOS auth)

    _usingiOSIntegratedLogin = YES;
    [FBSession openActiveSessionWithReadPermissions:nil
                                       allowLoginUI:YES
                                  completionHandler:completionHandler];
}
else
{
    // Either this is < iOS 6, or there's no Facebook account registered - request both
    // read and write permissions in order to avoid two trips to the Facebook app or web view

    _usingiOSIntegratedLogin = NO;

    NSMutableArray *permissions = [NSMutableArray arrayWithArray:[self publishPermissions]];
    [permissions insertObject:@"user_photos" atIndex:0];

    [FBSession openActiveSessionWithPermissions:permissions
                                   allowLoginUI:YES
                              completionHandler:completionHandler];
}

这篇关于将用户的Facebook凭证导入iOS6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆