2

I've an app with a today extension and a watch app. From the main app WCSession works fine and data is transferred to the watch and received correctly but when I try to send or receive data through the WCSession in the today widget the property paired and watchAppInstalled of the session are set to false so calling transferUserInfo: does nothing and session:didReceiveUserInfo: is never called.

I know I can open the app using openURL and then send the new data but I want to do that without leaving Notification Center. Does anyone know a nice workaround for this problem?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Marco Boschi
  • 2,321
  • 1
  • 16
  • 30

2 Answers2

5

It seems WCsession only works from the iOS app, not from any iOS extensions (share, today, keyboard, etc.), so for now you'll have to "relay" things via the app if you want to get it to the watch.

You should file an enhancement bug report with Apple explaining why you think it should be possible to use it from extensions too!

ccjensen
  • 4,578
  • 2
  • 23
  • 25
1

If the watch app is running in the foreground, you should be able to send it a message via a Darwin notification. Take a look at MMWormhole.

Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92
  • Thanks for the suggestion, I'll look into it. – Marco Boschi Aug 26 '15 at 08:07
  • Let's say I have the today widget and the watch app open but not the app, if the watch send a direct message to the app with sendMessage: the app should be opened in the background allowing it to receive userInfo and notify the widget through the wormhole. Could this work? – Marco Boschi Aug 26 '15 at 10:21
  • I would use [openParentApplication:reply](https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/#//apple_ref/occ/clm/WKInterfaceController/openParentApplication:reply:) to notify the app. Then you could use MMWormhole to notify the today extension. – Christopher Pickslay Aug 26 '15 at 20:09
  • Since the app is targeted for watchOS 2 `openParentApplication:reply:` is not available but `sendMessage:replyHandler:errorHandler:` method of WCSession does the same job. Do you have any idea on how to wake the app from notification center? – Marco Boschi Aug 27 '15 at 08:29
  • There is no way to directly wake the app from a today widget, except launching it with `openURL` – Christopher Pickslay Aug 27 '15 at 19:24