NSURLSessionUploadTask不调用委托方法NSURLSessionConfiguration backgroundSessionConfiguration

我正在尝试上传图像使用backgroundSessionConfigurationNSURLSessionUploadTask保持应用程序后台模式下的实时上传过程。

但是,当我使用backgroundSessionConfigurationNSURLSessionUploadTask不调用委托方法,而使用defaultSessionConfiguration它调用委托方法。

这是代码。

 //Create a file to upload UIImage *image = [UIImage imageNamed:@"1.jpg"]; NSData *imageData = UIImagePNGRepresentation(image); NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *URLs = [fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]; NSString *documentsDirectory = [[URLs objectAtIndex:0] absoluteString]; NSString *filePath = [documentsDirectory stringByAppendingString:@"testfile.jpg"]; [imageData writeToFile:filePath atomically:YES]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://file.upload/destination"]]; [request setHTTPMethod:@"PUT"]; NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfiguration: [NSString stringWithFormat:@"testSession.foo.com"]]; config.HTTPMaximumConnectionsPerHost = 1; session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; NSURLSessionUploadTask *uploadTask = [self.session uploadTaskWithRequest:request fromFile:[NSURL URLWithString:filePath]]; [uploadTask resume]; NSLog(@"==%ld",uploadTask.state); 

如果我更改backgroundSessionConfigurationdefaultSessionConfiguration ,委托方法将调用。

请帮我理解我错过了什么。

谢谢,Nitin