识别用户是否在 iOS 6 设置中定义了本地 facebook 帐户 [英] Recognize if user has defined a native facebook account in iOS 6 settings

查看:20
本文介绍了识别用户是否在 iOS 6 设置中定义了本地 facebook 帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过 FACEBOOK SDK 3.1 和 iOS 6 知道用户是否在 iPhone 设置中定义了他的 Facebook 帐户以供本地 facebook 使用?

Is there a way to know with FACEBOOK SDK 3.1 and iOS 6 if the user has defined his facebook account in the iPhone settings for native facebook use?

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

What I want to do is when opening my app, if the user has defined a "native facebook account" in iPhone setting, immediately show the "allow/don't allow" iOS 6 alert. But I want to do it only for native integration. What I mean, is that if know I can just try an "openSession" with FBSession, and it will show it, but if user has not defined the native account, I don't want the app to go to Safari or the facebook app. So I want to try to connect only if user has defined an account.

有人知道怎么知道吗?

推荐答案

这对我有用:

//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 6 设置中定义了本地 facebook 帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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