小编Jam*_*ley的帖子

在watchOS应用程序处于前台时处理推送通知?

我正在构建iOS + watchOS应用,这些应用需要在iOS和watch应用状态的所有可能组合中通知用户更新的信息:当iOS和watchOS都在前台运行时,当它们都在后台运行时,当一个或另一个在后台时。

我已经成功处理了这四种情况中的三种的推送通知。卡住的地方是手表应用在前台打开而iOS应用在后台-我找不到手表通知控制器,其ExtensionDelegate或在以下情况下会触发的iOS AppDelegate的任何方法:在这种情况下,将推送远程通知。

在iOS AppDelegate中,当iOS应用程序处于前台状态且观看应用程序处于任一状态时,在推送通知时将触发:

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            willPresent notification: UNNotification,
                            withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
Run Code Online (Sandbox Code Playgroud)

在WatchKit Extension NotificationController中,当iOS和watch应用都在后台时推送通知时将触发此事件:

override func didReceive(_ notification: UNNotification, withCompletion completionHandler: @escaping (WKUserNotificationInterfaceType) -> Swift.Void) { ... }
Run Code Online (Sandbox Code Playgroud)

但是,如果在推送通知时手表应用程序位于前台,而iOS应用程序位于后台,则通知横幅会出现在iPhone上(即使屏幕锁定),但我发现没有办法处理和更新除非当时手表也在后台。

有任何想法吗?

apple-push-notifications ios swift watchos watchos-3

3
推荐指数
1
解决办法
1122
查看次数