【问题标题】:`PFFile getDataInBackgroundWithBlock` block not getting called Obj-C`PFFile getDataInBackgroundWithBlock` 块没有被调用 Obj-C
【发布时间】:2015-01-05 09:44:26
【问题描述】:

我有以下代码,用于从 Parse 中检索图像。此代码块在一个递归循环中,该循环被调用以获取数组中的图像列表。

PFFile *remoteImageFile             =   object[@"Image"]
[remoteImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    DDLogInfo(@"%s:%d %@", __PRETTY_FUNCTION__, __LINE__, [error debugDescription]);
    // other logics
}];

代码成功获取了大部分图片,图片大小在 2MB 到 3MB 之间。但是对于某些文件,它随机失败,并且该块没有被触发,我的整个提取操作都冻结了。找不到原因。

请帮忙

【问题讨论】:

    标签: parse-platform objective-c-blocks


    【解决方案1】:

    我怀疑这里的 Parse 框架中存在错误。最可能的原因是您的 remoteImageFile 为零,这意味着甚至没有调用 getDataInBackgroundWithBlock:。 您可以使用以下代码进行检查吗:

    PFFile *remoteImageFile = object[@"Image"];
    if (remoteImageFile == nil || ![remoteImageFile isKindOfClass:[PFFile class]]) {
        NSLog(@"Error : remoteImageFile = %@", remoteImageFile);
    } else {
        [remoteImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
            DDLogInfo(@"%s:%d %@", __PRETTY_FUNCTION__, __LINE__, [error debugDescription]);
            // other logics
        }];
    }
    

    【讨论】:

    • 从昨天晚上检查您的代码并且没有发生冻结 :-) 惊喜!
    • 这应该是选择的答案。
    猜你喜欢
    • 2017-07-06
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多