每当从我的服务器发送静默通知时,都会触发以下功能:
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/