我打电话给doFacebookLogin我的应用程序切换到Facebook以授权应用程序但我允许该应用程序访问我的信息并切换回来。
什么都没发生。不,#34;完成"在控制台中。
如果我再次调用doFacebookLogin,控制台会显示
complete
Session state closed
这是我的代码。
- (void)doFacebookLogin:(id)sender
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,FBSessionState state, NSError *error) {
NSLog(@"complete");
[self sessionStateChanged:session state:state error:error];
}];
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error
{
NSLog(@"Session state changed");
switch (state) {
case FBSessionStateOpen:
NSLog(@"Session state open");
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if(error == nil) {
NSLog(@"%@", [user debugDescription]);
}
}];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
NSLog(@"Session state closed");
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if(error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
答案 0 :(得分:8)
你在AppDelegate有这个吗?
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
if ([[url scheme] hasPrefix:@"fb"]) {
return [FBSession.activeSession handleOpenURL:url];
}
.....
此外,您还需要在AppName-info.plist中检查您的应用是否具有适用于Facebook的网址类型部分