How to simulate the Local Notification in apple Watch App?

邮差的信 提交于 2019-12-28 10:44:13

问题


I am trying to simulate the local notification view in apple watch simulator. Does any one known how to simulate the local notifications in apple watch ?

I have done some research for that but didn't found any answer for the above. There is a way to simulate the PUSH NOTIFICATION but not for the LOCAL NOTIFICATION.


回答1:


It is not possible to have a Watch app react to a UILocalNotification in the simulator. However, it is almost identical to reacting to a push notification, except it gets routed through a couple of different methods.

If you're presenting an actionable notification, your WKUserNotificationInterfaceController subclass would override -didReceiveLocalNotification:withCompletion: instead of -didReceiveRemoteNotification:withCompletion:.

If your Watch app is getting launched in response to interacting with one of your actionable notifications, then your root WKInterfaceController would implement -handleActionWithIdentifier:forLocalNotification: or -handleActionWithIdentifier:forRemoteNotification:, as appropriate.

From WatchKit's point-of-view, those are the only distinctions between remote and local notifications.




回答2:


  1. Run your watch app (notification target) on simulator, dismiss the notification and stay on clock face.

  2. Switch to iOS simulator and create a notification. For testing purposes setup fireDate to something reasonable like:

    notification.fireDate = NSDate().dateByAddingTimeInterval(10)

  3. Here goes the trick. Hit ⌘L to lock iOS simulator.

  4. Enjoy notification arriving to watch app.



来源:https://stackoverflow.com/questions/27188862/how-to-simulate-the-local-notification-in-apple-watch-app

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