[英]Problems to login on facebook using social framework on ios
我正在使用此代碼進行Facebook登錄,並且在6.7版本的Facebook應用中運行良好。
當facebook應用程序的版本為6.8時,登錄不起作用! 有人可以想象發生了什么事嗎?
我正在使用的代碼是...
ACAccountType *facebookTypeAccount = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[self.accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:@{ACFacebookAppIdKey:facebookAppNumber, ACFacebookPermissionsKey: @[@"email"]}
completion:^(BOOL granted, NSError *error)
{
if(granted)
{
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookTypeAccount];
//NSLog(@"accounts %@",accounts);
self.facebookAccount = [accounts lastObject];
checkFbStatus = statusWaiting;
[self me];
userFbEmail = [jay valueForKey:INFO_FB_EMAIL];
facebookId = [jay valueForKey:INFO_FB_ID];
}
else
{
NSLog(@"one");
//aqui você
if([error code]== ACErrorAccountNotFound)
{
//[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook];
SLComposeViewController * fb = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
fb.view.hidden = YES;
[self presentViewController:fb animated:NO completion:nil];
checkFbStatus = statusFailed;
//Adicione sua conta de facebook nas configurações.
}
else
{
//Erro desconhecido ou então o usuário não deu permissão.
checkFbStatus = statusFailed;
}
}
} ];
我遇到了同樣的問題:
必須做出
@property (strong, nonatomic) FBSession *session;
in AppDelegate
in
(void)applicationDidBecomeActive:(UIApplication *)application { [FBAppEvents activateApp]; [FBAppCall handleDidBecomeActiveWithSession:self.session]; }
in
(void)applicationWillTerminate:(UIApplication *)application { [self.session close]; }
in
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:self.session]; }
in your settings class
if (appDelegate.session.isOpen) {
[FBSession setActiveSession:appDelegate.session];
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary *user, NSError *error) { [self registerationWithFBRequestConnection:connection andFBGraphUser:user andNSError:error]; }];
}
else
{
[appDelegate.session closeAndClearTokenInformation];
NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];
appDelegate.session = [[FBSession alloc] initWithPermissions:permissions];
[FBSession setActiveSession:appDelegate.session];
[appDelegate.session openWithBehavior:(FBSessionLoginBehaviorWithFallbackToWebView)
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { [self sessionStateChangedWithFBSession:session andFBSessionState:status andNSError:error]; }];
}
(void)sessionStateChangedWithFBSession:(FBSession*)session andFBSessionState:(FBSessionState)status andNSError:(NSError*) error { switch (status) { case FBSessionStateOpen: { [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary *user, NSError *error) {
[self registerationWithFBRequestConnection:connection andFBGraphUser:user andNSError:error];
}]; }
break;
case FBSessionStateClosed:
break;
case FBSessionStateClosedLoginFailed:
break;
default:
break;
} }
在您的registerationWithFBRequestConnection
方法中,您可以獲取所有登錄信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.