2013-05-17 13 views
5

Sto sviluppando un'applicazione per il posting del muro FB in ios utilizzando Facebook sdk 3.5. Sto usando due visualizzazioni. Una prima è una schermata iniziale e una seconda è la vista di accesso di Facebook. Quando sto attivare entrambe le viste che sto ricevendo un filo e l'errore visualizzati,FBSession: deve essere utilizzato solo da un singolo thread

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] * di terminazione app a causa di eccezione non identificata 'NSInternalInconsistencyException', motivo: 'FBSession: deve essere utilizzato solo da un unico filo' * stack di chiamate Prima laterale: (0x2387052 0x1fa3d0a 0x232fa78 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) terminare chiamato lancio di un'eccezione (lldb)

.515.053.691,36321 milioni

Ecco il mio codice 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]; 
    }]; 

E questo è il codice 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]; 
} 

Cqan qualsiasi aiuto ???

+0

Hey ragazzi qualsiasi soluzione su questo, per favore aiuto. http://stackoverflow.com/questions/22911458/app-is-crashing-due-to-assertion-failure-in-fbsession-checkthreadaffinity-f –

risposta

1

Sembra che tu stia accedendo all'istanza di FBSession da più thread. Verifica di non chiamare [FBSession activeSession] o qualcosa di simile da un thread in background (o che lo chiami sempre dallo stesso thread in background).

+0

Ho ricevuto lo stesso errore e l'ho trovato perché chiamo FBSession in un secondo filo (in un blocco) in un posto. Finalmente mi ricordi. Ma dove Facebook ha menzionato questo? @arunmak – JerryZhou

Problemi correlati