gpt4 book ai didi

ios - 将用户的 Facebook 凭据导入 iOS6

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:24 25 4
gpt4 key购买 nike

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

“在某些情况下,iOS 设备不会为已将应用程序连接到其 Facebook 帐户的用户提供访问 token 。当用户使用应用程序的网站或在其他移动设备上使用该应用程序时,可能会发生这种情况. 要使用 iOS 6 原生 Auth Dialog,应用程序需要将用户的凭据“导入”到设备中,并且需要显示 iOS 6 原生 Auth Dialog。”

(参见 http://developers.facebook.com/docs/howtos/ios-6/ ,提示 2)

我想知道如何导入这些数据,我找不到代码示例。

谢谢,

蒂姆

附言出于信息(和测试目的),很容易在应用中重现上述情况:

  1. 在设置应用中,删除 Facebook 帐户
  2. 在正在开发的应用程序中通过 SSO 连接到 Facebook,(考虑到没有在 iOS6 下注册的 Facebook 帐户,它应该回退到这个
  3. 在设置应用中重新设置 Facebook 帐户
  4. 再次尝试通过正在开发的应用程序登录。这次它将仍然通过 SSO 访问 Facebook,因为 token 是使用它创建的。

最佳答案

正如 MrNickBarker 所建议的那样,解决方案是让用户退出 SSO。但是,我只希望在完全确定这样做时用户将通过 iOS 6 身份验证系统重新登录时才这样做。

我的问题是我不知道有什么方法可以确保用户通过“设置”应用程序登录到 Facebook,而且我不想让用户退出 Facebook 只是为了让他们返回到每次都用于 SSO 登录的 Facebook 应用程序。

ACAccountStore 方法都不会告诉您用户是否已将他们的 Facebook 详细信息输入到“设置”应用程序中,但我最终发现 [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] 正是这样做的。

解决方法如下:

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

关于ios - 将用户的 Facebook 凭据导入 iOS6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12749027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com