0

I've got an AppleWatch app that is working fine in Simulator and Device, but when I call openParentApplication, it appears that the parent app is crashing immediately because I see this in the console output:

The UIApplicationDelegate in the iPhone App never called reply()...

When I try to manually launch the parent iOS app in the Simulator it crashes there too immediately. I don't have time to attach the debugger (which is already attached to the AppleWatch app) to see what is crashing it. Note that the parent app runs fine when the AppleWatch is running and I'm using a real iPhone. I can also run the app fine on the Simulator when not debugging the AppleWatch app.

I've tried resetting the Simulator, but problem persists.

I'm just not sure how to debug this. Any help is appreciated.

Daniel
  • 8,794
  • 4
  • 48
  • 71
  • 1
    I had a similar problem with my app. It turned out that my parent app crashed only when starting in background mode. See [my answer here](http://stackoverflow.com/questions/29750310/watchkit-handlewatchkitextensionrequest-multiple-instances/29765448#29765448) – zisoft May 22 '15 at 05:22

3 Answers3

1

Start an explicit background task in handleWatchKitRequest. Otherwise, your app gets killed before it reaches reply().

Refer to this post for a code example on how to create a background task.

Community
  • 1
  • 1
John
  • 8,468
  • 5
  • 36
  • 61
  • thanks, but I changed handleWatchKitRequest to just call reply(nil) and it still happens. And the app is still not launching when launched manually on Simulator. I also made didFinishLaunching return immediately. Some low level issue, perhaps unrelated to executing code, seems like it's in play. Confused. – Daniel May 22 '15 at 07:43
1

In turns out that after commenting out all code in the parent app's didFinishLaunching and stripping almost all code out of the watch extension, the problem was indeed at a lower level.

The Simulator has a

Debug | Open System Log...

menu option that showed the crash logs, which contained:

Dyld Error Message: Library not loaded: @rpath/MyCore.framework/MyCore Referenced from: /Users/me/Library/Developer/CoreSimulator/Devices/A2061705-DDDF-477C-9AAA-E50GG43A6350/data/Containers/Bundle/Application/DEB7FB25-8233-4B9F-8DAB-9FF8AE42BF33/MyApp.app/MyApp Reason: no suitable image found. Did find: /Users/me/Library/Developer/CoreSimulator/Devices/A2061705-DDDF-477C-9AAA-E50FF43A6350/data/Containers/Bundle/Application/DEB7FB25-8553-4B9F-8DAB-9FF8AE95BF33/MyApp.app/Frameworks/MyCore.framework/MyCore: mach-o, but wrong architecture

My Swift app has a few dependent Swift projects that are used by the app and extension. Getting the Swift frameworks to link has been a major pain. I've included the dependent frameworks (compiled in the same workspace) as embedded binaries. This works when running on the device, or on the Simulator, but not when running in this hybrid watch app + parent app Simulator context.

I changed the embedded binary references to point to the frameworks under ...DerivedData...Debug-iphonesimulator, as opposed to ...DerivedData...Debug-iphoneos, and the problem went away.

Still hoping the Swift framework story will improve.

Daniel
  • 8,794
  • 4
  • 48
  • 71
  • I have this problem too but I am using cocoapods to manage the 3rd party libraries. Can you help me? What do you mean with "I changed the embedded binary references to point to the frameworks under ...DerivedData...Debug-iphonesimulator, as opposed to ...DerivedData...Debug-iphoneos," sorry but I didn't understand what to do exactly – Lolloz89 Sep 09 '15 at 21:08
  • @Lolloz89 where there's your first problem, using cocoapods – TheCodingArt Apr 20 '17 at 21:50
0

Are you seeing an actual crash? That message has appeared for me plenty of times without the host app crashing.

99% of the time, that error appears because developers aren't opening a background task to complete their work in handleWatchKitRequest. Without the background task, the OS kills your app in the background before it has a chance to reply.

bgilham
  • 5,909
  • 1
  • 24
  • 39
  • @bgiham I made the handleWatchKitRequest just do this: reply(nil), and I still get the same console output. But I'm assuming the app is somehow aborting because I can't launch it manually in the iPhone simulator. Actually, I made didFinishLaunching return immediately, and I still don't see anything but the initial launch image then it goes away. – Daniel May 22 '15 at 01:22
  • Without some code examples, it will be hard to debug this for you. – bgilham May 22 '15 at 01:39