【问题标题】:findObjectsInBackgroundWithBlock in dispatch block doesn't called调度块中的 findObjectsInBackgroundWithBlock 未调用
【发布时间】:2015-03-23 15:58:07
【问题描述】:

我试图在另一个调度块中调用下面的解析检索方法,但它从不调用。我怀疑在另一个块中调用一个块是不允许的,但不确定。有人知道为什么不调用 findObjectsInBackgroundWithBlock 吗?

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
PFQuery *query = [PFQuery queryWithClassName:@"quotes"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {

            NSMutableArray *tempQuotes = [[NSMutableArray alloc] init];
            for (PFObject *object in objects) {

                [tempQuotes addObject:[object objectForKey:@"quote"]];
            }

            quotes = tempQuotes;

        }
    }];

 dispatch_async(dispatch_get_main_queue(), ^{

        [self.delegate postRefreshing];
    });
});

【问题讨论】:

    标签: ios objective-c parse-platform dispatch


    【解决方案1】:

    我如下更改了我的内部解析查询(没有任何背景块)并且它有效。我应该知道,如果您已经在调度块中,则不能在后台调用方法。

    PFQuery *query = [PFQuery queryWithClassName:@"quotes"];
    NSArray* quotesArray = [query findObjects];
    

    【讨论】:

    • 仅供参考:GCD 绝对支持在另一个已调度的块内调度一个块。如果这不起作用,则它必须是 Parse 框架中的某些内容或其他代码。
    • 也许 Parse 中有一些东西,但上面的实现现在对我有用。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2021-10-30
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多