我将facebook与我自己的应用程序集成以进行登录,并且我与本机facebook集成并且代码正在关注。现在,当设置中没有添加帐户时,会发生什么?> Facebook或如果添加了帐户,然后用户在浏览器中更改了同一帐户的密码,而不是在设置中我想要将用户拖到iPhone的Facebook应用程序登录,或者如果没有应用程序,那么我想跳转用户从浏览器登录。 这是我的代码。
_accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
FB_APP_ID, ACFacebookAppIdKey,
[NSArray arrayWithObject:@"email"], ACFacebookPermissionsKey,
nil];
[_accountStore requestAccessToAccountsWithType:FBaccountType options:options completion:
^(BOOL granted, NSError *e) {
if (granted)
{
NSArray *accounts = [_accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with single sign on
_facebookAccount = [accounts lastObject];
ACAccountCredential *facebookCredential = [_facebookAccount credential];
NSString *accessToken = [facebookCredential oauthToken];
NSLog(@"Facebook Access Token: %@", accessToken);
_facebookAccount = [accounts lastObject];
_facebookToken = [facebookCredential oauthToken];
NSLog(@"facebook account =%@",_facebookAccount);
}
else
{
NSLog(@"%@",e);
NSLog(@"%d",e.code);}
答案 0 :(得分:0)
使用Facebook SDK。要更改优先级,您可以更改行为, FBSessionLoginBehavior(枚举)。
-(void)loginFacebookWithCompletion:(RTLoginHandler)handler
{
// Initialize a session object
FBSession *session = [[FBSession alloc] init];
// Set the active session
[FBSession setActiveSession:session];
// Open the session
[session openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error)
{
if(status == FBSessionStateOpen)
{
// You get a opened session here
}
}];
}