lallu
lallu

Reputation: 23

Background task execution is not working as expected

I have a requirement to make an web-service call up on tapping actionable buttons from the Remote notification.

On the Remote notification, we have two buttons "Details" and "Fetch". "Fetch" is a background action (Activation Mode = UIUserNotificationActivationModeBackground) and will send some data with out launching the app.

On tapping "Fetch", i made a web-service call to send some details which i got from remote notification.

I have used NSURLSession to send those data to server.

NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"com.applewatch.sample"];

self.session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:nil];

NSURLSessionUploadTask *dataTask = [self.session uploadTaskWithRequest:mutableURLRequest fromData:nil];
[dataTask resume];

This works fine when the app is in active state but not in the suspended mode. What i meant to say here is, Once we get the Remote notification and if act after 1 hour on the notification, the service request is not going through.

I suspect, the service request is not going through because the app is in suspended mode/termination mode.

Could some help me how to make service calls in the background.

Note: I have not enabled "Background Fetch" options in info.plist.

Let me know if need to enable and implement the service calls in the UIApplication delegate

application:performFetchWithCompletionHandler:

Upvotes: 0

Views: 342

Answers (1)

Leonardo
Leonardo

Reputation: 1750

I'm not being able to recall or find again where I read this information before, but try using

- uploadTaskWithRequest:fromFile:

I believe it's the only upload method that will work in background

Upvotes: 1

Related Questions