0

I have an iOS application and a companion watchOS application. iOS app provides access token for watchOS app when watchOS app starts for the first time. After this watchOS app starts to get data updates from the server periodically by sending NSURLSessionDownloadTask requests.

My NSURLSession is configured following way:

NSURLSessionConfiguration *config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:[[[[NSBundle mainBundle] bundleIdentifier] stringByAppendingString:@".backgroundsession"] stringByAppendingString:[NSUUID UUID].UUIDString]];
config.sharedContainerIdentifier = APP_GROUPS_ID;
self.urlSession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];

Then I send requests periodically following way:

NSURL *url = [NSURL URLWithString:API];
NSMutableURLRequest *request = [self buildRequestForURL:url andMethod:@"POST"];

NSString *body = [NSString stringWithFormat:<some request params>];

[request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];

[[self.urlSession downloadTaskWithRequest:request] resume];

watchOS app successfully receives updates for some time. It successfully receives updates when iOS app is in background mode or even when it is manually unloaded.

But watchOS app stops receiving updates when I lock iPhone screen (right after or after a couple of minutes).

Has anybody experienced the same issue with watchOS apps?

Narmo
  • 595
  • 4
  • 11

1 Answers1

0

Take a look at This Apple Example - WatchBackgroundRefresh, and my answer to this question. Hopefully that can lead you to some working code.

Jens Peter
  • 715
  • 6
  • 10