0

我有一本在存档后写入文件的字典[NSKeyedArchiver archivedDataWithRootObject:dictionary]。我获取文件内容并将存档数据通过多对等设备传输到我的对等设备。然后,在我的对等设备中,我使用[NSKeyedUnarchiver unarchiveObjectWithData:data]. 但是,它在取消归档时返回 nil,尽管其中存在数据。

我怀疑文件中的内容很大。NSkeyedArchiver/有什么替代方案NSKeyedUnarchiver吗?

代码:归档:

[[NSKeyedArchiver archivedDataWithRootObject:dictionary] writeToFile:fileAtPath options:NSDataWritingAtomic error:&error];

转让:

[NSData dataWithContentsOfFile:fileAtPath] ;

解档:

[NSKeyedUnarchiver unarchiveObjectWithData:data];
4

1 回答 1

0

尝试编写如下数据,

 [data writeToFile:filePath atomically:NO];

这里data指的是[NSKeyedArchiver archivedDataWithRootObject:dictionary]您的存档数据。

否则存档和未存档的方法很好。

希望这会有所帮助:)

于 2016-05-13T10:49:33.563 回答