从缓存中获取数据时PFFile崩溃

时间:2015-11-08 12:47:21

标签: ios parse-platform pffile

最近,在Parse SDK更新之后,我在启动时加载文件时开始出现以下异常:

2015-11-08 13:23:15.088 MyApp[7219:471946] [Error]: Caught "NSInvalidArgumentException" with reason "*** -[_NSPlaceholderData initWithContentsOfFile:options:error:]: nil file argument":
(
0   CoreFoundation                      0x0000000110a07f45 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000011047edeb objc_exception_throw + 48
2   CoreFoundation                      0x0000000110a07e7d +[NSException raise:format:] + 205
3   Foundation                          0x000000011002cd48 -[NSData(NSData) initWithContentsOfFile:options:error:] + 95
4   Foundation                          0x00000001100c5fcc +[NSData(NSData) dataWithContentsOfFile:options:error:] + 61
5   MyApp                               0x000000010e828426 -[PFFile _cachedData] + 94
6   MyApp                               0x000000010e886cac __62-[BFTask continueWithExecutor:successBlock:cancellationToken:]_block_invoke + 83
7   MyApp                               0x000000010e88658c __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 + 82
8   MyApp                               0x000000010e8874ab __29+[BFExecutor defaultExecutor]_block_invoke_2 + 358
9   MyApp                               0x000000010e887a15 -[BFExecutor execute:] + 65
10  MyApp                               0x000000010e886510 __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke + 138
11  MyApp                               0x000000010e886110 -[BFTask runContinuations] + 396
12  MyApp                               0x000000010e8859c6 -[BFTask trySetResult:] + 151
13  MyApp                               0x000000010e883c4c -[BFTaskCompletionSource trySetResult:] + 79
14  MyApp                               0x000000010e7e48b3 __28-[PFAsyncTaskQueue enqueue:]_block_invoke_2 + 198
15  MyApp                               0x000000010e88658c __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 + 82
16  libdispatch.dylib                   0x00000001145fce5d _dispatch_call_block_and_release + 12
17  libdispatch.dylib                   0x000000011461d49b _dispatch_client_callout + 8
18  libdispatch.dylib                   0x0000000114605bef _dispatch_root_queue_drain + 1829
19  libdispatch.dylib                   0x00000001146054c5 _dispatch_worker_thread3 + 111
20  libsystem_pthread.dylib             0x000000011494ea9d _pthread_wqthread + 729
21  libsystem_pthread.dylib             0x000000011494c3dd start_wqthread + 13
).

为什么PFFile会崩溃?这是否意味着本地缓存与以前的版本不兼容,并且当用户更新应用程序时我会遇到很大的问题?

1 个答案:

答案 0 :(得分:0)

问题是我正在创建一个新的PFFile,将其分配给某个对象的列本地,而不是将其保存回Parse。创建新文件时,它的url属性为nil,这应该没问题,因为它还没有在线。在那之后,我正在获取孩子就是那个文件的父对象 - 这最终搞砸了,因为我关闭了应用程序,下次打开时我试图用PFFile来获取url的数据属性等于nil。这导致上述例外情况。一个来自Parse的人提出的解决方法:

PFFile *file = object[fileKey];
if ((file != nil) && [file isKindOfClass:[PFFile class]] && (file.url == nil)) {
    [object revertObjectForKey:fileKey];
}

在获取对象之后,将从Parse服务器中获取正确的数据。