NSURLSessionUploadTask does not call a delegation method with NSURLSessionConfiguration backgroundSessionConfiguration

I am trying to upload an image using backgroundSessionConfiguration and NSURLSessionUploadTask in order to maintain live broadcast in the background of the application.

But when I use backgroundSessionConfiguration , NSURLSessionUploadTask does not call the delegation method when using defaultSessionConfiguration , it calls the delegation method.

Here is the code.

 //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); 

if I change backgroundSessionConfiguration to defaultSessionConfiguration , it will call the delegate method.

Please help me understand what I am missing.

Thanks Nitin

0
ios objective-c nsurlsession nsurlsessionuploadtask
Sep 22 '15 at 12:49
source share

No one has answered this question yet.

See similar questions:

5
How to get backgroundSession response NSURLSessionUploadTask

or similar:

928
How do I call Objective-C code from Swift?
661
How to create delegates in Objective-C?
224
iOS - calling the application delegation method from ViewController
2
NSURLSessionUploadTask get response data
2
NSURLSessionUploadTask does not load image with parameters
one
Are temporary files saved by NSURLSessionUploadTask
one
NSURLSessionUploadTask and API Requests
0
NSURLSessionUploadTask - specify a range of content
0
NSUrlSessionUploadTask The delegate method calls twice



All Articles