How to trigger notifications using WatchKit

十年热恋 提交于 2019-12-03 22:44:06

I'm hoping I don't have to call the watchKit's controller local/remote notification handlers directly.

No, you don't.

The answer is XCode doesn't support debugging Apple Watch and iPhone simultaneously for now. That's why you can't push a notification from iPhone simulator to Watch simulator, only payload test by *.apns files is supported for now.

Its explained in Notification Essentials that

iOS decides whether to display that notification on the iPhone or on Apple Watch .

So I dont think(as of now) there is anything that can be done from the app to trigger Notifications specifically in the watch.

Edit: It looks like theres a bug in 8.2 beta.

WatchKit Known Issues

When viewing a notification in iOS simulator, clicking on the notification icon or body does not launch the corresponding Watch app

Release notes

Dreamwieber

In order to test watch notifications, you must first create a new build scheme.

Duplicate your watch app scheme, and in the "Run" section, choose your custom notification as the executable.

Now you can run the notification scheme.

Inside the extensions group in your project, under Supporting Files is a file called PushNotificationPayload.json.

You can edit the payload file to try different notifications and categories.

Source

I only had two targets when I created the projects:

  • [app name]
  • [app name] Watch App

Editing the Watch App scheme allows me to select another executable -- notably there's the Glance and Notification options there, and they work for me. Just select it, close, and run. I haven't tried duplicating the targets/schemes so I don't have to edit them, but I don't think that would be an issue.

Edit: Actually, the SDK tells you to edit the scheme too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!