您能帮我怎样获取用户信息。
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
}
}];
上述代码-异步?如何使其同步?告诉我有关机制或告诉我在哪里阅读。谢谢!
最佳答案
好像您完全搞砸了。尝试下面的代码,但是请确保您理解它:
- (void) SetUserData
{
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
self.first_name = [result objectForKey:@"first_name"];
NSLog(@"First name just came from server: first_name: %@", self.first_name);
}
else
{
}
}];
[self furtherProcessMethod];
}
- (void) furtherProcessMethod
{
if (self.first_name == nil)
{
// this is not recursion, do not miss that!!
[self performSelector:@selector(furtherProcessMethod) withObject:nil afterDelay:2.0];
}
else
{
NSLog(@"First name that I can work with first_name: %@", self.first_name);
// here you can handle you first_name, after it came
}
}
因此,一段时间后,您需要登录:
名字只是来自服务器:first_name:一些名字
我可以使用first_name使用的名字:一些名字