我正在敲打我的头,因为我在应用程序关闭时失去了这个会话.我已经附上了我的appDelegate.
AppDelegate.m
#import "AppDelegate.h"@implementation AppDelegateNsstring *const FBSessionStateChangednotification=@"ro.Tag:FBSessionStateChangednotification";- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // OverrIDe point for customization after application launch. [self openSessionWithAllowLoginUI:NO]; NSLog(@"%@",[[FBSession activeSession] accesstoken]); return YES;}- (voID)applicationDIDBecomeActive:(UIApplication *)application{ // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was prevIoUsly in the background,optionally refresh the user interface. // We need to properly handle activation of the application with regards to SSO // (e.g.,returning from iOS 6.0 authorization dialog or from fast app switching). [FBSession.activeSession handleDIDBecomeActive];}/* * 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"); NSLog(@"session %@",session); } 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]; //NSLog(@"permissions: %@",permissions); 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]; } @end解决方法 谢谢你们的评论.幸运的是,我终于能够追查这个问题了.发生的事情是我从根视图控制器移动了我的逻辑,但仍然有一个调用
[self openSessionWithAllowLoginUI:NO]
所以这意味着我连续两次打电话.一旦进入appDelegate并再次进入根视图控制器.第二个电话似乎清除我的令牌自动登出我.一旦我能够识别出这个并从我的根视图控制器中删除功能,一切都按预期工作.
谢谢你的帮助.
总结以上是内存溢出为你收集整理的关闭应用程序时,IOS会丢失FBSession全部内容,希望文章能够帮你解决关闭应用程序时,IOS会丢失FBSession所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)