gpt4 book ai didi

c++ - 在 objective-c ++ 中尝试 IOS facebook SDK

转载 作者:太空宇宙 更新时间:2023-11-04 13:57:34 25 4
gpt4 key购买 nike

我正在尝试为 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 是异步的,所以我尝试将它放在第一个函数中以在同一线程上运行,但无济于事。

有什么帮助吗? (我对 objective-c 很陌生,但对大多数其他语言都有经验)

最佳答案

I think the FBRequest is asynchronous, so I tried placing it in the first function to run on the same thread, to no avail.

我认为您完全没有理解“异步”的含义。您不必为异步事物设置线程——您可以在同一个线程上异步执行某些操作。 (虽然在这种情况下它可能在另一个线程上完成它的主要工作,然后在原始线程上运行完成 block 。)

当您调用异步 API 时,完成 block 不会在函数的其余部分之前执行。几乎可以保证。

关于c++ - 在 objective-c ++ 中尝试 IOS facebook SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20779881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com