ios - 识别用户是否在 iOS 6 设置中定义了 native facebook 帐户

标签 ios facebook authentication native account

有没有办法知道 FACEBOOK SDK 3.1 和 iOS 6 用户是否在 iPhone 设置中定义了他的 facebook 帐户以供 native facebook 使用?

我想做的是在打开我的应用程序时,如果用户在 iPhone 设置中定义了“ native facebook 帐户”,则立即显示“允许/不允许”iOS 6 警报。但我只想为本地集成做这件事。 我的意思是,如果知道我可以尝试使用 FBSession 的“openSession”,它会显示它,但是如果用户没有定义 native 帐户,我不希望该应用程序转到 Safari 或 facebook 应用程序.所以我只想在用户定义了一个帐户时才尝试连接。

有人知道怎么知道吗?

最佳答案

这对我有用:

//Step 1. create and store an ACAccountStore in an ivar
ACAccountStore* as = [[ACAccountStore alloc] init];
self.accountStore = as;
[as release];

//Step 2. Get the facebook account type
//Do not use the constant if you are in iOS5, use this string:@"com.apple.facebook"
ACAccountType* at = [self.accountStore accountTypeWithAccountTypeIdentifier: @"com.apple.facebook"];

//Step 3. request access to the facebook account, passing your facebook app id
__block typeof(self) bself = self;
[self.accountStore requestAccessToAccountsWithType:at
                            options:@{(NSString *)ACFacebookAppIdKey: kFBAppId }
                         completion:^(BOOL granted, NSError *error)
 {
     //Step 4. Check if the account is integrated natively
     //Note: if granted is NO, check for the error to see what's going on.
     BOOL nativeAccount = granted == YES && [bself.accountStore accountsWithAccountType:at];


     //Step 5. clean the account store.
     bself.accountStore = nil;
 }];

关于ios - 识别用户是否在 iOS 6 设置中定义了 native facebook 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13929776/

相关文章:

ios - 来自字符串的日期在 iOS 中不起作用

javascript - facebook graph api ajax XMLHttpRequest - 空结果?

ruby-on-rails-3 - 将 ActiveAdmin 用户与现有用户模型合并

.net - 限制对记录的访问。基于声明的权限是个好主意吗

iphone - MKOverlay 有时会消失

ios - 一个 segue - 几个按钮

iphone - 在 IOS 中使用 native 控件进行本地化

javascript - 如何提取直接 facebook 视频 url

java - Facebook SDK 4.0.0,Android 上的 ShareDialog 始终为 null

angularjs - 使用 AngularJS 进行身份验证、使用 REST Api WS 进行 session 管理和安全问题