Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wake up iPhone app from watchOS 2?

I have an app that has a very rich network layer and my apple watch app depends on all the models. Unfortunately the app is not modular enough to make this layer available in the watch app.

I solved this problem by using openParentApplication: to wake up the iPhone app, perform the request and give back the results.

In watchOS 2 this method is gone and I should use WatchConnectivity. The best way to use this would be by sending userInfo dictionaries.

But how can I wake up the iPhone app to handle my requests? To get notifications about new userInfos I have to use the WCSessionDelegate and for that I need a WCSession object. But when should I create that? And how to wake up the app?

like image 858
Ben Avatar asked Jul 24 '15 19:07

Ben


People also ask

Where is Wake screen on Apple Watch app?

Wake the Apple Watch display Your Apple Watch sleeps again when you lower your wrist. Tap the display or press the Digital Crown. Turn the Digital Crown upward.

How do I bypass sleep mode on Apple Watch?

If you want to exit and unlock Sleep Mode temporarily, turn the Digital Crown. To turn Sleep Mode off entirely, swipe-up Control Center and tap the Bed Sleep Mode icon once to turn it off. If you don't want to go through this manual turning Sleep Mode on and off, you can also create a bedtime schedule on your watch.


1 Answers

I asked an Apple Engineer about this and got the following tip: The iOS-App should be started in a background-task. So the following worked for me pretty well:

UIApplication *application = [UIApplication sharedApplication];

__block UIBackgroundTaskIdentifier identifier = UIBackgroundTaskInvalid;
dispatch_block_t endBlock = ^ {
    if (identifier != UIBackgroundTaskInvalid) {
        [application endBackgroundTask:identifier];
    }
    identifier = UIBackgroundTaskInvalid;
};

identifier = [application beginBackgroundTaskWithExpirationHandler:endBlock];

Add this to your session:didReceiveMessage: or session:didReceiveMessageData: method to start a background task with a three minute timeout.

like image 140
Ben Avatar answered Nov 15 '22 15:11

Ben