7

FACEBOOK SDK 3.1 と iOS 6 で、ユーザーが iPhone の設定で自分の Facebook アカウントをネイティブ Facebook 用に定義しているかどうかを知る方法はありますか?

私がやりたいことは、アプリを開くときに、ユーザーが iPhone 設定で「ネイティブ facebook アカウント」を定義している場合、すぐに「許可/許可しない」iOS 6 アラートを表示することです。しかし、ネイティブ統合のためだけにやりたいです。つまり、FBSession で「openSession」を試すことができることがわかっている場合、それは表示されますが、ユーザーがネイティブ アカウントを定義していない場合、アプリを Safari または facebook アプリに移動させたくないということです。 . したがって、ユーザーがアカウントを定義している場合にのみ接続を試みたいと思います。

誰かが知る方法を知っていますか?

4

1 に答える 1

2

これは私のために働いています:

//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;
 }];
于 2013-08-27T17:31:21.277 に答える