How to show notification in watch kit , where iPhone app is already showing the notifications

折月煮酒 提交于 2019-12-24 17:29:55

问题


I have an app which shows notification in iPhone. Now I am trying to show the same notification in WatchKit or in iWatch. So do I need to recopy all the functionalities I already did in ViewController and AppDelegate of iPhone app in Watchkit Extension or is there some common interface to notify the watch to show the notification, only UI I need to provide.


回答1:


iOS will decide to send notification to apple watch or to iPhone.

If your iPhone is active then notification will come to iPhone. If your iPhone is locked then notification will come to Apple Watch.

Did you have checked "Include Notification Scene" while adding target of watchkit app?

If yes then you can see notification class and WKUserNotificationInterface static interface in your storyboard.

You can also customize notification screen at dynamic interface.

If you want to handle notification then implement below method in screen which will display after click on notification in apple watch.

override func handleActionWithIdentifier(identifier: String?,
    forRemoteNotification remoteNotification: [NSObject : AnyObject])
{

}

Please look at this link: https://developer.apple.com/library/watchos/documentation/General/Conceptual/WatchKitProgrammingGuide/CustomzingthePushNotificationInterface.html



来源:https://stackoverflow.com/questions/33550276/how-to-show-notification-in-watch-kit-where-iphone-app-is-already-showing-the

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