Apple Watch and iPhone Are Not Connected When The App in Phone Goes to Background

Apple watch app does not work when iPhone app is in terminated state?

You'll need to handle the request in the iPhone app a bit differently in order for your app to not be killed off by the OS. I've shared a similar answer here: https://stackoverflow.com/a/29848521/3704092

Can I keep my WatchKit App running in the background on the Apple Watch?

Not possible. Because Apple Document for watchkit clearly mentions that "WatchKit extensions do not support background execution modes,they run only while the user is interacting with the corresponding app on Apple Watch.".

You can refer apple document Link to Apple Doc

Read Communicating Directly with Your Containing iOS App.

Location Services not working in background called by WatchKit

Three things to check and be aware of:

  1. Location Permissions like [self.locationManager requestAlwaysAuthorization]; are only acknowledged once by the OS. If you have already requested permission, doesn't matter the level, the OS will NOT display a request to the user. The OS will just pass over the request and leave the permission level as is. The only time you can be assured that the OS will display the request to the user is if the [CLLocationManager authorizationStatus] returns kCLAuthorizationStatusNotDetermined. In every other case, you must manually request permission by displaying an Alert or other form of UI display. Also note that the OS retains whether or not it already displayed the request, even if you delete your app and reinstall it. So to test, you need to reset your Simulator's Content or your iPhone's Location Privacy.

  2. Make sure you have added the plist keys for NSLocationAlwaysUsageDescription AND NSLocationWhenInUseUsageDescription If you don't add this to your plist, the OS will ignore any Location Permission Requests.

  3. If you want to use requestAlwaysAuthorization to get location data from the phone (not the watch app extension) while the phone app is in the background, will also require you register for Background Modes Location updates under Project>Target>Capabilities.

UPDATE
Use a background task to give your app time to respond when in the background. Something like this:

-(void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *replyInfo))reply{

UIApplication *app = [UIApplication sharedApplication];

UIBackgroundTaskIdentifier bgTask __block = [app beginBackgroundTaskWithName:@"watchAppRequest" expirationHandler:^{

[[UIApplication sharedApplication] endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;

}];

//make your calls here to your tasks, when finished, send the reply then terminate the background task

//send reply back to watch
reply(replyInfo);

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[app endBackgroundTask:bgTask];
bgTask=UIBackgroundTaskInvalid;
});
}


Related Topics



Leave a reply



Submit