【问题标题】:NSKeyedUnarchiver unarchiveObjectWithData: in Parse block function never returnsNSKeyedUnarchiver unarchiveObjectWithData:在 Parse 块函数中永远不会返回
【发布时间】:2015-02-05 00:39:51
【问题描述】:

我从 Parse.com 请求 NSDictionary 的文件表示(是的,我知道还有其他更明显的方法来存储字典),然后在完成块中,数据被取消归档并分配给属性。

当这段代码执行时,它似乎永远不会从 unarchive 行返回。没有冻结,没有错误或异常。该应用程序继续运行,好像一切都很好。如果我在 unarchiver 行和它之后的行设置断点,第一个断点会被命中,但第二个断点永远不会。

我可以确认该函数已返回此文件的预期数据量。

PFFile *definitionFile = appObject[@"myFile"];  //PFFile reference from a PFObject
[definitionFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    if (!error) {
        if (data) {
            //A breakpoint on the following line does fire and show that there is data being given to the unarchiver
            self.pendingDefinition = (NSDictionary *) [NSKeyedUnarchiver unarchiveObjectWithData:data];
        }
        //////Nothing beyond this point gets executed////////
        [self handleNewDefinition];
    } else {
        NSLog(@"ERROR");
    }
}];

【问题讨论】:

  • parse 发送给你的数据是用 NSKeyedArchiver 编码的吗? NSKeyedUnarchiver 只取消归档已经用 NSKeyedArchiver 编码的对象
  • 就是这样。数据被存储为 plist。需要使用 plist 序列化。

标签: ios parse-platform nskeyedunarchiver


【解决方案1】:

事实证明,数据被存储为 plist,我需要使用 plist 序列化来提取它:

if (data) {
            NSError *error;
            NSPropertyListFormat format;
            NSDictionary* plist = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:&error];
            if(!plist){
                NSLog(@"Error: %@",error);
            }

【讨论】:

    猜你喜欢
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    相关资源
    最近更新 更多