Objective C块-如何提取块数据(Facebook SDK) [英] Objective C Block - How to extract Blocks Data (Facebook SDK)

查看:86
本文介绍了Objective C块-如何提取块数据(Facebook SDK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经受了几个小时的痛苦.

I am suffering with it a few hours now.

我正在尝试使用iOS的Facebook SDK 3.5 Facebook API 检索数据.当我使用方法startWithCompletionHandler()发出请求时,它似乎没有调度新线程,因为它等待整个函数结束,并且仅在执行块内容之后.因此,我无法读取该类其他区域中的userData内容.

I am trying to retrieve data from the Facebook API using the Facebook SDK 3.5 for iOS. When I issue a request using the method startWithCompletionHandler() it does not seem to dispatch a new thread, as it waits for the whole function to end, and only afterwards the block content is executed. So I am not able to read the userData contents in other areas of the class.

我曾尝试过使用信号灯,但是它似乎总是陷入僵局.

I have tried with semaphores but it always seems to fall in a deadlock.

userData 是全局的.

FBRequest *request = [FBRequest requestForMe];        
    // Send request to Facebook
    [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (!error) {
            // result is a dictionary with the user's Facebook data
            userData = (NSDictionary *)result;

            NSLog(@"Block return: %@",userData[@"id"]);

        } else{
            NSLog(@"Facebook Initialization error: %@", error);
        }
    }
     ];

推荐答案

尝试一下:

[[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
    if (error) {
    }
    else {

        [self StopSpinner];

        txtID.text = user.id;
        txtUserName.text = user.username;
        txtName.text = user.name;
        txtEmail.text = [user objectForKey:@"email"];
    }
}];

这篇关于Objective C块-如何提取块数据(Facebook SDK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆