我已經使用facebook SDK與Facebook進行身份驗證。當在設置中啓用然後通過點擊按鈕的應用程序沒有Facebook賬戶進入Safari瀏覽器進行身份驗證,即ACAccountType始終顯示0個帳戶
if (appDelegate.session.state != FBSessionStateCreated)
{
appDelegate.session = [[FBSession alloc] init];
}
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// and here we make sure to update our UX according to the new session state
[self updateView];
}];
否則,如果Facebook帳戶啓用然後
NSArray *fbAccounts=nil;
ACAccountType *accountTypeFB;
if ((_accountStore = [[ACAccountStore alloc] init]) &&
(accountTypeFB = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook])){
fbAccounts = [_accountStore accountsWithAccountType:accountTypeFB];
NSLog(@" %d fbAccounts",[fbAccounts count]);
}
if ([fbAccounts count]!=0) {
[FBSession openActiveSessionWithAllowLoginUI:YES];
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"email",
nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (error) {
NSLog(@"Failure");
NSLog(@"error %@",error);
}
else
{
NSLog(@" active session opened ");
if (self.gotUserDetails)
{
return;
}
[self fetchuserinfo];
}
}];
}
}
這顯示提醒以訪問用戶信息的圖像。它在模擬器中工作正常。但在設備中,它總是去Safari瀏覽器或Facebook應用程序進行身份驗證,即使在設置中啓用了Facebook帳戶。請幫我找出這個問題。
感謝所有。
你是否調用過'requestAccessToAccountsWithType:options:completion:'? – Wain
@我應該在哪裏調用它? –