How can I check that an NSData blob is valid as resumeData for an NSURLSessionDownloadTask?

后端 未结 3 673
时光取名叫无心
时光取名叫无心 2020-12-23 23:33

I have an app that\'s using background downloads with the new NSURLSession APIs. When a download cancels or fails in such a way that NSURLSessionDownloadT

3条回答
  •  渐次进展
    2020-12-24 00:31

    I have not found an answer to how to tell if the data is valid ahead of time.

    However, I am presently working around the issue like so:

    NSData *resumeData = ...;
    NSURLRequest *originalURLRequest = ...;
    NSURLSessionDownloadTask *downloadTask = nil;
    
    @try {
        downloadTask = [session downloadTaskWithResumeData:resumeData];
    }
    @catch (NSException *exception) {
        if ([NSInvalidArgumentException isEqualToString:exception.name]) {
            downloadTask = [session downloadTaskWithRequest:originalURLRequest];
        } else {
            @throw exception; // only swallow NSInvalidArgumentException for resumeData
        }
    }
    

提交回复
热议问题