这是我登录facebook的代码,当我完成登录后,FaceBookLogIn.xib不会正常解散,
当我退出应用程序并重新启动它时工作正常,我的主视图出现。
一旦用户唱歌,我怎么能解除viewcontroller?
的更新 的
我将app AppDelegate中的所有代码移动到我的主视图控制器
当我唱歌时,我会进入nslog
“2013-12-07 13:02:49.650 barbar [2275:70b]用户会话发现”
蝙蝠仍然认为不要忽视
如果我退出并返回应用程序,则会显示tabbarviewcontroler并获取我的nslog -
2013-12-07 13:06:42.162 barbar [2303:70b]用户登录Innnnn
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewDidAppear:(BOOL)animated{
if (FBSession.activeSession.state
== FBSessionStateCreatedTokenLoaded) {
NSLog(@"User Logged Innnnn");
//[self dismissViewControllerAnimated:YES completion:Nil];
}
//create and present the login view controller
else {
NSLog(@"the user not login");
FacebookConect * showfacebookconnectview = [[FacebookConect alloc]initWithNibName:@"FacebookConect" bundle:Nil];
[self presentViewController:showfacebookconnectview animated:YES completion:Nil];
}
animated = YES;
}
- (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");
[self dismissViewControllerAnimated:YES completion:Nil];
}
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];
}
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
/*
we pass this permissions array into our request
I only request email, but there are many more options
*/
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"email",
nil];
return [FBSession
openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
- (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];
}
@end
答案 0 :(得分:0)
我不建议使用AppDelegate直接显示登录屏幕。看起来您正在使用Storyboards / Xib来显示您的界面。出于这个原因,我允许默认操作发生(因为您通过手动设置rootViewController
属性来阻止它)。然后,在主视图控制器中,检查Facebook是否会显示对话框(presentViewController:animated:completion:
),然后可以按上述方式解除,并显示原始主视图控制器。