Jul*_*tea 6 facebook login objective-c ios
我的iOS应用程序使用Facebook登录,但我的开发团队最近决定将我们的所有应用程序整合到一个具有通用APP ID的通用Facebook应用程序中.所以我进入我的项目并尝试将我的FacebookAppID和URL类型更改为正确的APP ID,但是当我运行应用程序并单击登录按钮时,它会重定向我以登录我在Facebook上的旧应用程序.我完全不知道为什么会这样,但这是我在AppDelegate文件中的内容:
/*
Callback for session changes
*/
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"User session found");
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
/*
* Opens a Facebook session and optionally shows the login UX.
*/
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"email",
@"user_games_activity",
@"user_location",
@"user_likes",
@"user_birthday",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
/*
* If we have a valid session at the time of openURL call, we handle
* Facebook transitions by passing the url argument to handleOpenURL
*/
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
/*
*Logout
*
*/
- (void) closeSession {
[FBSession.activeSession closeAndClearTokenInformation];
}
Run Code Online (Sandbox Code Playgroud)
您的设备上可能有两个应用程序Info.plist中具有相同Facebook URL方案的应用程序.你可以:
您可能有多个URL方案.如果是这样,您应该查找看起来像fbxxxxxxxxxxx的那个,它显示在http://developers.facebook.com/上的应用页面上