NSURLSession with invalid resume data

前端 未结 2 1718
不知归路
不知归路 2021-01-01 04:15

I use [NSURLSessionConfiguration defaultSessionConfiguration] to config my url session.

I pause a task by calling cancelByProducingResumeData:

相关标签:
2条回答
  • 2021-01-01 04:53

    Anytime you relaunch your app, everything under tmp will be cleaned, I was experiencing the same thing, even though I tried to copy all the *.tmp, and paste back whenever app relaunches, it'll throw an error

    My advice is that, you check if the *.tmp file is accessible, redownload from start if not

    0 讨论(0)
  • 2021-01-01 05:01

    I encountered this problem. I found that sandbox path will change after the application restart in iOS8. But the resumeData record the old sandbox path, that let the download task can’t find the resumeData. So I update the sandbox path recorded in sandbox by key ‘NSURLSessionResumeInfoLocalPath’, it does work:

    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:resumeDataPath];
    NSString *resumeDataFileName = [dic[@"NSURLSessionResumeInfoLocalPath"] lastPathComponent];
    NSString *newTempPath = NSTemporaryDirectory();
    NSString *newResumeDataPath = [newTempPath stringByAppendingPathComponent:resumeDataFileName];
    [dic setValue:newResumeDataPath forKey:@"NSURLSessionResumeInfoLocalPath"];
    [dic writeToFile:resumeDataPath atomically:YES];
    
    0 讨论(0)
提交回复
热议问题