xcode 如何在 Apple Watch App 中模拟本地通知?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27188862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:16:32  来源:igfitidea点击:

How to simulate the Local Notification in apple Watch App?

objective-cxcodewatchkit

提问by NSAnant

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 ?

我正在尝试在 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.

我为此做了一些研究,但没有找到上述任何答案。有一种方法可以模拟 PUSH NOTIFICATION 但不适用于 LOCAL NOTIFICATION。

回答by Dave DeLong

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

不可能让 Watch 应用程序对UILocalNotification模拟器中的a 做出反应。但是,它几乎与对推送通知做出反应相同,只是它通过几种不同的方法进行路由。

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

如果您要呈现可操作的通知,您的WKUserNotificationInterfaceController子类将覆盖-didReceiveLocalNotification:withCompletion:而不是-didReceiveRemoteNotification:withCompletion:.

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

如果您的 Watch 应用程序是为了响应与您的可操作通知之一的交互而启动的,那么您的根目录WKInterfaceController将根据需要实施-handleActionWithIdentifier:forLocalNotification:-handleActionWithIdentifier:forRemoteNotification:

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

从 WatchKit 的角度来看,这些是远程通知和本地通知之间的唯一区别。

回答by Viktor Kucera

  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.

  1. 在模拟器上运行您的手表应用程序(通知目标),关闭通知并停留在钟面上。

  2. 切换到 iOS 模拟器并创建通知。出于测试目的,将 fireDate 设置为合理的值,例如:

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

  3. 诀窍就在这里。按 ?L 锁定 iOS 模拟器。

  4. 享受到达观看应用程序的通知。