ios - 如何在 iOS 中触发 didReceiveRemoteNotification?

标签 ios swift push-notification apple-push-notifications

每当从我的服务器发送静默通知时,都会触发以下功能:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    print("Received Silent Notification")

}
但是,此功能仅在应用程序在屏幕上可见时触发(也就是在前台)。如果我点击主页按钮,然后从我的服务器发送静默通知,我的沙盒设备上不会触发任何内容。
我正在用户注册时构建电子邮件验证系统,而服务器轮询将无法大规模运行。
这就是我的 Info.plist 的样子:
<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>
    <string>processing</string>
    <string>remote-notification</string>
</array>
这是沙盒错误吗?当应用程序在后台时,如何触发上述功能?

最佳答案

尝试使用application(_:didReceiveRemoteNotification:fetchCompletionHandler:)当应用程序在前台或后台运行时,系统会调用此方法。而您使用的委托(delegate)方法仅在应用程序在前台运行时才被调用。

关于ios - 如何在 iOS 中触发 didReceiveRemoteNotification?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62563654/

相关文章:

ios - iOS 中的静态页脚

ios - 应用程序在没有协议(protocol)功能的情况下编译 - 为什么?

ios - Swift - 可选属性的 JSON 序列化

ios - 如何使用 NSObject 属性

php - 永远运行 PHP 脚本以在 HostGator 上推送通知

android - 无法使用 Cordova 推送通知插件获取设备 token

ios - 如何定义嵌入 ViewController 的 NavigationController?

iphone - 不使用 iPhone 时关闭加速计

swift - 导航栏下方的菜单在 Swift 中带有动画

android - Phonegap 多推送通知,当打开一个并返回时,它会从托盘中删除我的所有通知 - Android