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

后端 未结 3 661
时光取名叫无心
时光取名叫无心 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:25

    This is the workaround suggested by Apple:

    - (BOOL)__isValidResumeData:(NSData *)data{
        if (!data || [data length] < 1) return NO;
    
        NSError *error;
        NSDictionary *resumeDictionary = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:NULL error:&error];
        if (!resumeDictionary || error) return NO;
    
        NSString *localFilePath = [resumeDictionary objectForKey:@"NSURLSessionResumeInfoLocalPath"];
        if ([localFilePath length] < 1) return NO;
    
        return [[NSFileManager defaultManager] fileExistsAtPath:localFilePath];
    }
    

    Edit (iOS 7.1 is not NDA'd anymore): I got this from a Twitter exchange with an Apple engineer, he suggested what to do, and I wrote the above implementation

提交回复
热议问题