NSURLSessionResumeCurrentRequest

NSURLSessionResumeCurrentRequest

我有一个来自cancelByProducingResumeData的resumeData的字典:像下面这样,我想知道如何使用NSURLSessionResumeCurrentRequest为HTTPHeaderField添加值。

而且我不知道如何将NSURLSessionResumeCurrentRequest的NSData转换为NSURLRequest。

2014-11-11 13:11:30.545 xxxxXXXXX [77997:14163248] resumeInfo => {
NSURLSessionDownloadURL =“http://xxx.xxx.xxx/webdav/content/admin/201407/ttp.mp4”;
NSURLSessionResumeBytesReceived = 50737920;
NSURLSessionResumeCurrentRequest = ;
NSURLSessionResumeEntityTag = 41220469dd0d761e33125751d386d9b1;
NSURLSessionResumeInfoLocalPath =“/用户/库/开发人员/ CoreSimulator /设备/ 0F13C2EC-4B9C-4FB4-AD78-7A309C4C65F2 / data /容器/数据/应用程序/ 28925A91-9DDE-4041-A1F5-A35387E9115E / tmp / CFNetworkDownload_”;
NSURLSessionResumeInfoVersion = 1;
NSURLSessionResumeOriginalRequest = ;
NSURLSessionResumeServerDownloadDate =“星期五,2014年7月25日04:36:22 GMT”;

最佳答案

我尝试使用以下代码更改请求,非常成功! ;)

- (NSData *)regenerateResumeData:(NSData *)originData
{
    NSString *error;
    NSPropertyListFormat format;
    NSMutableDictionary* plist = [NSMutableDictionary dictionaryWithDictionary:[NSPropertyListSerialization propertyListFromData:originData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error]];

    NSData *currentRequest = [plist objectForKey:@"NSURLSessionResumeCurrentRequest"];
    NSURLRequest *request = [(NSURLRequest *)[NSKeyedUnarchiver unarchiveObjectWithData:currentRequest] copy];
    NSMutableURLRequest *mutableRequest = [request mutableCopy];
    [mutableRequest addValue:[plist objectForKey:@"NSURLSessionResumeEntityTag"] forHTTPHeaderField:@"If-Match"];
    [mutableRequest addValue:[NSString stringWithFormat:@"bytes=%@-", [plist objectForKey:@"NSURLSessionResumeBytesReceived"]] forHTTPHeaderField:@"Range"];
    request = [mutableRequest copy];

    NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:request];

    [plist removeObjectForKey:@"NSURLSessionResumeCurrentRequest"];
    [plist setValue:archivedData forKey:@"NSURLSessionResumeCurrentRequest"];

    return [NSPropertyListSerialization dataFromPropertyList:plist format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error];
}

10-08 16:57