应用程序被杀后,使用NSURLSessionUploadTask恢复上传任务?

我使用以下代码使用NSURLSessionUploadTask上传图像

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; NSURL *URL = [NSURL URLWithString:@"http://example.com/upload"]; NSURLRequest *request = [NSURLRequest requestWithURL:URL]; NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"]; NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromFile:filePath progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { if (error) { NSLog(@"Error: %@", error); } else { NSLog(@"Success: %@ %@", response, responseObject); } }]; [uploadTask resume]; 

我的文件正确地上传到服务器上,但如果应用程序在上传过程中被杀死,那么我无法通过获取会话标识符然后恢复后恢复上传状态。

在谷歌搜索后,我发现下面的委托方法将被调用(在重新启动我的应用程序之后)如果我的上传被中断,但在我的情况下似乎没有调用此方法。

 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(nullable NSError *)error; 

我使用正确的方法来识别会话标识符还是有其他方法来实现我的要求?