Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 由于-[FBSession checkThreadAffinity]、';FBSession:只能从单个线程使用';_Ios_Facebook_Thread Safety - Fatal编程技术网

Ios 由于-[FBSession checkThreadAffinity]、';FBSession:只能从单个线程使用';

Ios 由于-[FBSession checkThreadAffinity]、';FBSession:只能从单个线程使用';,ios,facebook,thread-safety,Ios,Facebook,Thread Safety,我在应用程序中使用facebook SSON。当我调用我的方法[self-openSessionWithAllowLoginUI:NO]时;在块内,它将崩溃,并显示以下错误消息 *** Assertion failure in -[FBSession checkThreadAffinity], /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBSession.m:1571 Terminating app due to uncaught exceptio

我在应用程序中使用facebook SSON。当我调用我的方法[self-openSessionWithAllowLoginUI:NO]时;在块内,它将崩溃,并显示以下错误消息

   *** Assertion failure in -[FBSession checkThreadAffinity], /Users/chrisp/tmp/build-sdk/ios-sdk/src/FBSession.m:1571
  Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FBSession: should only be used from a single thread'
  *** First throw call stack:
  (0x2f2c2fd3 0x39a42ccf 0x2f2c2ead 0x2fc6fd5b 0x407c27 0x4050a5 0x406ab1 0x405c43 0x40662d 0x39f2a833 0x39f2a81f 0x39f2a777 0x2f28d8f1 0x2f28c1c5 0x2f1f6f4f 0x2f1f6d33 0x340fb663 0x31b4216d 0x7fdc7 0x2f0c0)
 libc++abi.dylib: terminating with uncaught exception of type NSException
我知道它说的是我从两个或多个线程调用FBSession,我应该从一个线程调用它,但是我没有得到我调用这个线程的其他地方

我的代码是:-

-(void)facebook
{
ACAccountStore  *accountStore;
accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:kFACEBOOK_APPID,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];
[accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
 ^(BOOL granted, NSError *e) {
     if (granted)
     {
         NSArray *accounts = [accountStore accountsWithAccountType:FBaccountType];
         if ([accounts count] == 0) {
         }
         else{
             ACAccount *facebookAccount;
             NSLog(@"Facebook account Found");
             facebookAccount = [accounts firstObject];
             ACAccountCredential *facebookCredential = [facebookAccount credential];
             NSString *accessToken = [facebookCredential oauthToken];
             NSLog(@"Facebook Access Token: %@", accessToken);
             NSLog(@"facebook account =%@",facebookAccount);
         }
     }
     else
     {
         NSLog(@"error getting permission %@",e);
         [self openSessionWithAllowLoginUI:NO];
     }
 }];
}
但是,如果我不是从块中的调用,它工作正常,但是我需要直接从需要在块中调用它的设置应用程序实现Facebook SSO

没有阻塞,我这样称呼它:

-(void)facebook
{
ACAccountStore  *accountStore;
accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:kFACEBOOK_APPID,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];
[self openSessionWithAllowLoginUI:NO];

}
如果您需要更多的代码,请告诉我。

试试看

dispatch_async(dispatch_get_main_queue(), ^{ 

   [self openSessionWithAllowLoginUI:NO]; 

}); 

你能把代码行放在调用方法的地方吗?
facebook
?我只需点击一个按钮就可以调用它。尝试执行dispatch_async(dispatch_get_main_queue(),^{[self openSessionWithAllowLoginUI:NO];});多谢了,伙计,它起作用了。完美的请加上它作为答案。我已加上它作为答案。。