iOS 8.4 - didFinishLaunchingWithOptions is no longer called for first watchkit extension request

Hi,

we upgraded one of our phones to iOS 8.4 and noticed an important lifecycle change from iOS 8.3 to iOS 8.4.


Starting point:

Watchkit app is available on watch, parent iPhone app is not running.


In iOS 8.3:

  1. Watchkit app calls WKInterfaceController.openParentApplication
  2. The parent iPhone app gets launched and AppDelegate.application:didFinishLaunchingWithOptions:
  3. AppDelegate.application:handleWatchKitExtensionRequest: is executed


In iOS 8.4:

  1. Watchkit app calls WKInterfaceController.openParentApplication
  2. AppDelegate.application:handleWatchKitExtensionRequest: is executed directly


This caused a major issue in our app because we rely on application:didFinishLaunchingWithOptions doing the required setup for us on app start. I am sure that other apps will have similar issues since application:didFinishLaunchingWithOptions is often used to initialize 3rd party libs.


This could easily be reproduced by shutting down the app on the iPhone.


I filed a bug (#21652770) for this issue

It looks like you may need to create a background task as mentioned in the "tips" - https://forums.developer.apple.com/message/5380#5380

I've tried that, but that doesn't seem to work. Here's an extremely bare bones project I made and submitted to Apple in a bug report: https://www.dropbox.com/s/ayltpprjck37ins/HandleWatchkitExtensionError%202.zip?dl=0


You can see the first time you press the button in the Watch app, you get the error below. Susequent calls will succeed until you open and kill the app via Multitasking.


(Warn ) WatchKit: <SPCompanionAppServer.m __91-[SPCompanionAppServer launchCompanionAppForGizmoAppWithIdentifier:withUserInfoData:reply:]_block_invoke_2:1450> Got BSActionErrorCodeResponseNotPossible for com.alarm.Testing123.watchkitapp. This will translate to WatchKitApplicationDelegateWatchKitRequestReplyNotCalledError


error: Error Domain=com.apple.watchkit.errors Code=2 "The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]" UserInfo=0x60800007d800 {NSLocalizedDescription=The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}, reply: (null)

Every watchkit request is handled in a background task.

I fixed the problem by ensuring that the required app initialization is done either on application:didFinishLaunchingWithOptions or before the first AppDelegate.application:handleWatchKitExtensionRequest:

Sorry, could you explain how exactly you solved it?


I moved my Parse initialization to another method and call it in application:handleWatchKitExtensionRequest: only for the first call (indicated with an instance variable bool).

But it still doesn't seem to initialize 3rd party libs.

This is exactly what I did.


Best way to see what's happening in your app is to use a

[NSThread sleepForTimeInterval:5]; at the beginning of application:handleWatchKitExtensionRequest:

This will give you enough time to attach to the parent app process (XCode -> Attach to Process -> <Your app name>)

Hi,


Just stumbled upon this behavior after updating to 8.4. I've checked and it is as you said, didFinishLaunchingWithOptions is called after handleWatchKitExtensionRequest, completely ruining my watch app (currently developing a workaround).


Is this change even documented anywhere? Why does Apple keeps insisting in changes like this (it isn't the first time)? Could someone from Apple provide with a decent explanation?

I'm experiencing the same problem and it's incedibly annoying.This bug has made openParentApplication very unstable. I tried to get around the problem by calling openParentApplication again in those cases. Here's my thread about the topic in SO:

http://stackoverflow.com/questions/31210092/inconsistent-behavior-of-openparentapplication-in-my-watchkit-app/31241597#31241597

Hi, all.

My workaround is to run WKInterfaceController openParentApplication twice.

You can have a try.

iOS 8.4 - didFinishLaunchingWithOptions is no longer called for first watchkit extension request
 
 
Q