gpt4 book ai didi

ios facebook 用户信息

转载 作者:行者123 更新时间:2023-11-29 02:51:52 24 4
gpt4 key购买 nike

你能帮我怎样才能得到用户信息。

  NSString *name;
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
// Success! Include your code to handle the results here
name = [result objectForKey:@"first_name"]; // Error!!! how to get data from this handler
}
else
{
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
}

}];

上述代码 - 异步?如何使其同步?告诉我有关机制或告诉我在哪里阅读。谢谢!

最佳答案

您可以在此站点上阅读有关 Facebook SDK 的所有内容:https://developers.facebook.com .

他们不提供同步 API,我什至不知道您为什么需要它。但如果你真的这样做了,你可以做一些解决方法。查看实现:

__block id result = nil;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);

[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id theResult, NSError *error) {
result = theResult;
dispatch_semaphore_signal(semaphore); // UPDATE: dispatch_semaphore_wait call was here, which is wrong
}];

dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
NSLog(@"%@", result);// this code will be launched after you've received response from Facebook

Result 符合FBGraphUser 协议(protocol)。因此,如果它不包含 first_name 键的值,用户就不会指定它。您可以在调试器中打印 result 并查看它是什么。

关于ios facebook 用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24392164/

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