我正在尝试为IOS facebook SDK创建一个C ++桥。我可以很好地登录,但是当我尝试检索用户详细信息时,尽管可以在调试器中跨过图形功能,但似乎从未执行过图形功能。这是我所拥有的:
void facebook_bridge::performLoginWithFacebook()
{
// Open a session showing the user the login UI
// You must ALWAYS ask for basic_info permissions when opening a session
[FBSession openActiveSessionWithReadPermissions:@[@"basic_info", @"email"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
// Retrieve the app delegate
AppController* appDelegate = (AppController*)[UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
[appDelegate sessionStateChanged:session state:state error:error];
}];
isLoggedIn = true;
}
cocos2d::CCDictionary* facebook_bridge::getUserDetails()
{
__block NSDictionary *currentPermissions;
// Request the permissions the user currently has
[FBRequestConnection startWithGraphPath:@"/me/permissions"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
// These are the current permissions the user has
currentPermissions= [(NSArray *)[result data] objectAtIndex:0];
NSLog(@"No error");
// We will store here the missing permissions that we will have to request
// If we have permissions to request
} else {
NSLog([NSString stringWithFormat:@"error %@", error.description]);
}
}];
cocos2d::CCDictionary* dict = cocos2d::CCDictionary::create();
for(int i = 0; i < currentPermissions.count; i++) //get a bad access here, currentPermissions is always null
{
NSString* val = currentPermissions.allValues[i];
NSString* k = currentPermissions.allKeys[i];
std::string value = *new std::string(val.UTF8String);
std::string key = *new std::string(k.UTF8String);
cocos2d::CCString *ccVal = cocos2d::CCStringMake(value);
dict->setObject((cocos2d::CCObject*)ccVal, key);
}
dict->retain();
return dict;
}
我认为FBRequest是异步的,因此我尝试将其放在第一个函数中以在同一线程上运行,但无济于事。
有什么帮助吗?(我对目标C还是很陌生,但是有大多数其他语言的经验)
我认为FBRequest是异步的,因此我尝试将其放在第一个函数中以在同一线程上运行,但无济于事。
我认为您完全错过了“异步”的含义。您不必具有线程即可使事物异步化-您可以在同一线程上异步执行某些事物。(尽管在这种情况下,它可能在另一个线程上执行其主要工作,然后在原始线程上运行完成块。)
当您调用异步API时,完成功能块将在功能的其余部分之前执行。几乎可以保证。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句