在目标 c++ 中尝试 IOS facebook SDK
Attempting IOS facebook SDK in objective c++
我正在尝试为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 时,完成块不会在函数的其余部分之前执行。几乎可以保证。
相关文章:
- 使用ios:ate写入到流会覆盖现有文件
- 如何访问RTCVideoRenderer的帧?(ios)
- ios::fmtflags 在 C++ 中是如何工作的?setf() 是如何工作的?
- 我可以在 iOS 或 mac 应用程序中使用C++代码吗?
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- 为什么 C++ 11 在 ios 类中添加了运算符 bool
- 'string'文件在带有C++文件的iOS插件上找不到
- 文件模式标志"ios::app"是否用于删除文件(如果文件已存在)?
- 使用 C++ iOS::ate 获取错误的文件大小
- 使用 适用于 Android 和 iOS 的 tf-lite C++ API
- 如何正确设置 ios 标志以进行流操作?
- 在为 iOS 构建 aws-sdk-cpp 时,cmake 上的 CXX 编译器错误已损坏
- C++ std::locale( "en" ) 在 iOS 上引发异常
- 在瓦尔格林德的泄漏摘要中使用 std::ios::sync_with_stdio(fasle) 打印时获取"still reachable"
- 在iOS应用程序中创建数据库
- Qt & Firebase C++ SDK 在 iOS 上的链接问题
- 是否有可以在iOS上运行的API来更改现有视频的每秒帧数?
- 将文件从 iOS 应用程序加载到 C++ 对象中/<iostream>iOS 上的问题
- 将原始 IOS 相机数据上传到纹理
- 在目标 c++ 中尝试 IOS facebook SDK