5

Facebook SDK 3.5を使用して、iosでFBウォール投稿用のアプリを開発しています。私は2つのビューを使用しています。1 つ目はスプラッシュ スクリーンで、2 つ目は Facebook のログイン ビューです。両方のビューをアクティブにすると、スレッドとエラーが表示されます。

 2013-05-17 17:07:59.115 [415:12503] * Assertion failure in -[FBSession checkThreadAffinity], /Users/chrisp/tmp/sdk/ios-sdk/src/FBSession.m:1571

2013-05-17 17:07:59.127 [415:12503] * キャッチされない例外 'NSInternalInconsistencyException' が原因でアプリを終了します。 0x1a9c2db 0x21fa2 0x1e626 0x1ecd9 0x22b67 0x1eba3 0x3c265 0x2388ec9 0x11165c2 0x111655a 0x11bbb76 0x11bc03f 0x11bb2fe 0x113ba30 0x113bc56 0x1122384 0x1115aa9 0x293ffa9 0x235b1c5 0x22c0022 0x22be90a 0x22bddb4 0x22bdccb 0x293e879 0x293e93e 0x1113a9b 0x2be2 0x2b15) terminate called throwing an exception(lldb)

これが私の Appdelegate.m コードです。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
   // Override point for customization after application launch.

 self.viewController = [[[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil]autorelease] ;

 // self.loginViewController = [[secondview alloc] initWithNibName:@"secondview"
 //                                                                  bundle:nil];
 // self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.loginViewController];

 // self.navigationController.delegate = self;

 //  self.window.rootViewController = self.navigationController;


   self.window.rootViewController = self.viewController;

   [self.window makeKeyAndVisible];
   return YES;

   //
   //
   UIBackgroundTaskIdentifier backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{NSLog(@"BackgroundTask Expiration Handler is called");
     [application endBackgroundTask:backgroundTask];
   }];

これは facebook_view.m コードです

     - (void)viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];

   self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
   self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidUnload {
   [self setFBLoginView:nil];
   [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - FBLoginView delegate

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
   // Upon login, transition to the main UI by pushing it onto the navigation stack.
      TNLRadioAppDelegate *appDelegate = (TNLRadioAppDelegate *)[UIApplication sharedApplication].delegate;
  [self.navigationController pushViewController:((UIViewController *)appDelegate.viewController) animated:YES];
}
- (void)loginView:(FBLoginView *)loginView
     handleError:(NSError *)error{
   NSString *alertMessage = nil, *alertTitle;

   // Facebook SDK * error handling *
   // Error handling is an important part of providing a good user experience.
   // Since this sample uses the FBLoginView, this delegate will respond to
   // login failures, or other failures that have closed the session (such
   // as a token becoming invalid). Please see the [- postOpenGraphAction:]
   // and [- requestPermissionAndPost] on `SCViewController` for further
   // error handling on other operations.

   if (error.fberrorShouldNotifyUser) {
       // If the SDK has a message for the user, surface it. This conveniently
       // handles cases like password change or iOS6 app slider state.
       alertTitle = @"Something Went Wrong";
       alertMessage = error.fberrorUserMessage;
   } else if (error.fberrorCategory == FBErrorCategoryAuthenticationReopenSession) {
       // It is important to handle session closures as mentioned. You can inspect
       // the error for more context but this sample generically notifies the user.
       alertTitle = @"Session Error";
       alertMessage = @"Your current session is no longer valid. Please log in again.";
   } else if (error.fberrorCategory ==
FBErrorCategoryUserCancelled) {
       // The user has cancelled a login. You can inspect the error
       // for more context. For this sample, we will simply ignore it.
       NSLog(@"user cancelled login");
   } else {
       // For simplicity, this sample treats other errors blindly, but you should
       // refer to https://developers.facebook.com/docs/technical-guides/iossdk/errors/ for more information.
       alertTitle  = @"Unknown Error";
       alertMessage = @"Error. Please try again later.";
       NSLog(@"Unexpected error:%@", error);
   }

   if (alertMessage) {
       [[[UIAlertView alloc] initWithTitle:alertTitle
                                   message:alertMessage
                                  delegate:nil
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil] show];
   }
}

- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView {
   // Facebook SDK * login flow *
   // It is important to always handle session closure because it can happen
   // externally; for example, if the current session's access token becomes
   // invalid. For this sample, we simply pop back to the landing page.
   TNLRadioAppDelegate *appDelegate = (TNLRadioAppDelegate *)[UIApplication sharedApplication].delegate;
   if (appDelegate.isNavigating) {
       // The delay is for the edge case where a session is immediately closed after
       // logging in and our navigation controller is still animating a push.
       [self performSelector:@selector(logOut) withObject:nil afterDelay:.5];
   } else {
       [self logOut];
   }
}

- (void)logOut {
   [self.navigationController popToRootViewControllerAnimated:YES];
}

誰か助けてくれませんか???

4

1 に答える 1

1

複数のスレッドから FBSession インスタンスにアクセスしているようです。[FBSession activeSession] などをバックグラウンド スレッドから呼び出していないこと (または常に同じバックグラウンド スレッドから呼び出していること) を確認してください。

于 2013-07-31T10:21:40.213 に答える