-[FBSession checkThreadAffinity]中的断言失败导致应用程序崩溃,"FBSession:仅应从单个线程使用" [英] app is crashing due to Assertion failure in -[FBSession checkThreadAffinity], 'FBSession: should only be used from a single thread'
问题描述
我在我的应用程序中使用facebook SSON.当我调用我的方法时[self openSessionWithAllowLoginUI:NO];在该块内,其崩溃并显示以下错误消息.
I am using facebook SSON in My application. When i am calling my method [self openSessionWithAllowLoginUI:NO]; Within the block, its crashing with the following error Message.
*** 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一样,在这里我应该从单个线程中调用它,但是我无法在其他地方调用此线程.
I know it says something like i am calling the FBSession from two or more threads, where as i should call it from a single thread but i am not getting where else i am calling this thread.
我为此的代码是:-
-(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.
But if i am not calling from with in the block its working fine, But I need to implement Facebook SSO directly from settings app for which it need to be called with in the block.
在没有阻止的情况下,我这样称呼它:-
Without block I am calling it like this:-
-(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];
}
如果您需要更多代码,请告诉我.
Please let me know if you need more of the code.
推荐答案
尝试做
dispatch_async(dispatch_get_main_queue(), ^{
[self openSessionWithAllowLoginUI:NO];
});
这篇关于-[FBSession checkThreadAffinity]中的断言失败导致应用程序崩溃,"FBSession:仅应从单个线程使用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!