繁体   English   中英

当应用程序处于后台时,在静默推送通知时显示用户通知

[英]Display Usernotification upon silent Push Notification when app is in background

这是我的场景:我的应用收到一个带有有效负载的推送通知

"aps": {
            "content-available": 1,
            "alert": "hello",
            "sound": ""
          }

收到后,根据有效负载中的其他值,我决定是否显示 UserNotification :

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
 if mylogic = true{
 self.scheduleNotification(userInfo: userInfo, inSeconds: 1, completion: { success in
                    if success {
                      print("Successfully scheduled notification")
                    } else {
                      print("Error scheduling notification")
                    }
                  })
}
}

当应用程序在前台而不是在后台时,这可以正常工作

条件:-Development Profile -Untethered 调试 -Xcode 12 Beta

这是预期的行为吗?如果是这样,当应用程序在后台运行时,我如何设法显示用户通知?

好的,我已经阅读了一些文档...这里https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/如果发现以下内容:

“background 对于在后台传递内容的通知使用后台推送类型,并且不触发任何用户交互。如果您设置此推送类型,apns-topic header 字段必须使用您的应用程序的捆绑ID作为主题。”

这对我有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM