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

问题描述



有什么方法可以通过FACEBOOK SDK 3.1和iOS 6知道用户是否在iPhone设置中定义了他的Facebook帐户?想要做的是打开我的应用程序时,如果用户在iPhone设置中定义了本机Facebook帐户,请立即显示允许/不允许iOS 6警报。但是我只想做本地集成。
我的意思是,如果知道我可以尝试与FBSession的openSession,它会显示它,但如果用户没有定义本机帐户,我不希望该应用程序去Safari或Facebook应用程式。所以我想尝试连接,只有当用户已经定义了一个帐户。



任何人都知道一种方式知道?

解决方案

这对我有用:

 code> //步骤1.在ivar中创建和存储ACAccountStore 
ACAccountStore * as = [[ACAccountStore alloc] init];
self.accountStore = as;
[as release];

//步骤2.获取Facebook帐户类型
//如果您在iOS5中,请不要使用常量,请使用以下字符串:@com.apple.facebook
ACAccountType * at = [self.accountStore accountTypeWithAccountTypeIdentifier:@com.apple.facebook];

//步骤3.请求访问Facebook帐户,传递您的Facebook应用程序id
__block typeof(self)bself = self;
[self.accountStore requestAccessToAccountsWithType:at
options:@ {(NSString *)ACFacebookAppIdKey:kFBAppId}
完成:^(BOOL授予,NSError *错误)
{
//步骤4.检查帐户是否本地集成
//注意:如果被授予NO,请检查错误以查看发生的情况。
BOOL nativeAccount = granted == YES&&& [bself.accountStore accountsWithAccountType:at];


//步骤5.清理帐户商店。
bself.accountStore = nil;
}];


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?

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.

anyone knows a way to know?

解决方案

This is working for me:

//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帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 03:20
查看更多