(NSURLSessionDownloadTask cancelByProducingResumeData)崩溃nsnetwork守护程序iOS 7.0

时间:2014-08-13 23:18:50

标签: ios nsurlsession

在我的应用中,用户可以随时取消下载。我通过拨打[task cancelByProducingResumeData:取消下载。它在大多数情况下工作正常,但是,如果下载任务在启动/恢复后立即取消,它会崩溃nsnetwork守护程序。以下是导致守护程序在iOS 7.0上100%崩溃的示例代码。这个问题在iOS 7.1上不会发生!

NSURLSession *ses = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration backgroundSessionConfiguration:@"aaa"] delegate:self delegateQueue:nil];
NSURLSessionDownloadTask *dTask = [ses downloadTaskWithRequest:request];
[dTask resume];

[ses getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
    NSLog(@"%@", downloadTasks);
    if (downloadTasks.count>0)
    {
        for (NSURLSessionDownloadTask *task in downloadTasks)
        {
            NSLog(@"cancelling : %@", task);
            [task cancelByProducingResumeData:^(NSData *resumeData) {
                NSLog(@"Cancelled");
            }];
        }
    }
}];

以下是崩溃日志:

Aug 13 16:15:06 Dev-iPhone backgroundTesting[4848] <Warning>: (
        "<__NSCFBackgroundDownloadTask: 0x1659cf80>"
    )
Aug 13 16:15:06 Dev-iPhone backgroundTesting[4848] <Warning>: cancelling : <__NSCFBackgroundDownloadTask: 0x1659cf80>
Aug 13 16:15:06 Dev-iPhone nsnetworkd[4827] <Error>: Property list invalid for format: 100 (property lists cannot contain NULL)
Aug 13 16:15:06 Dev-iPhone nsnetworkd[4827] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: NSURLSessionDownloadTaskResumeData)'
    *** First throw call stack:
    (0x2e469e8b 0x387636c7 0x2e3a4f9b 0x2e08b3d3 0x2e0ccee1 0x38c48103 0x38c4ce77 0x38c49f9b 0x38c4d751 0x38c4d9d1 0x38d77dff 0x38d77cc4)
Aug 13 16:15:06 Dev-iPhone ReportCrash[4849] <Notice>: ReportCrash acting against PID 4827
Aug 13 16:15:06 Dev-iPhone ReportCrash[4849] <Notice>: Formulating crash report for process nsnetworkd[4827]
Aug 13 16:15:06 Dev-iPhone com.apple.launchd[1] (com.apple.nsnetworkd[4827]) <Warning>: (com.apple.nsnetworkd) Job appears to have crashed: Abort trap: 6

是否有解决方法安全取消下载而不会崩溃nsnetwork守护程序?谢谢!

1 个答案:

答案 0 :(得分:1)

查看异常,感觉守护程序无法生成恢复数据。当然这是iOS中的错误,但你可以做的解决方法是不允许取消,除非你收到一些字节,在这种情况下守护进程应该能够生成正确的恢复数据。