开发者社区> 问答> 正文

推送用户终止的通知背景

当应用程序处于被用户杀死的后台时,就会收到Push,当用户点击Push通知时,它会打开该应用程序,它不会崩溃,但它会立即关闭。

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired till the user taps on the notification launching the application.

        // With swizzling disabled you must let Messaging know about the message, for Analytics
        Messaging.messaging().appDidReceiveMessage(userInfo)

        // Print message ID.
        print("The userInfo is: \(userInfo)")

        completionHandler(UIBackgroundFetchResult.newData)
    }

之前的方法甚至没有被调用,也可能是,但我不知道如何调试它,因为应用程序没有运行。

下面是我通过服务器发送的通知对象:

apns: {
                payload: {
                    aps: {
                        alert: {
                            title: messageObject.authorName,
                            body: messageObject.content,
                        },
                        sound: "notification.wav",
                        category: "ChatViewController"
                    }
                }
            }

这就是通过服务器发送的内容。当应用程序处于后台而不是终止时,或者应用程序处于前台时,通知才能工作。

展开
收起
游客5akardh5cojhg 2019-12-11 22:02:26 326 0
0 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
内容安全检测与管控 立即下载
面向失败设计 立即下载
低代码开发师(初级)实战教程 立即下载