Ho usato Facebook SDK per l'autenticazione con Facebook. Quando non ci sono account facebook abilitata nelle impostazioni poi cliccando sulle applicazioni pulsante va a Safari per l'autenticazione cioèACAccountType mostra sempre 0 account
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];
}];
altrimenti se account facebook è abilitata,
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];
}
}];
}
}
Questo immagine che mostra l'avviso per accedere alle informazioni dell'utente. Funziona bene nel simulatore. Ma nel dispositivo va sempre in safari o in app di Facebook per l'autenticazione anche l'account facebook è abilitato nelle impostazioni. Per favore aiutami a trovare questo problema.
Grazie a tutti.
Avete chiamato 'requestAccessToAccountsWithType: options: completion:'? – Wain
@Wain dove dovrei chiamarlo? –