[英]IOS Weird behaviuor for background push notifications when app is killed
我想我已经通过网络阅读了所有可能的文档和所有可能的答案,但仍然无法完成这项工作:
使用 Firebase 云函数发送到 APNS 服务器
有 4 台设备:两台安装了 13.3.1(XR 和 SX Max),一台安装了 13.1 (6s),一台安装了 12 (6) ios
当所有手机在前台或后台时发送推送通知到达所有手机
当应用程序被杀死但仍连接到电源并有网络时,发送推送通知会到达除 ios 12 以外的所有手机
断电一段时间或失去网络连接后,即使再次插入手机并重新连接网络,XS max 停止接收通知,但XR和6S仍在接收它们。 ( didReceiveRemoteNotification:fetchCompletionHandler: not fire! )
我已经尝试了任何地方给出的每一个技巧和每一个建议。
目前正在开发中使用 Swift 4.2 并且该项目支持的 SDK 是 IOS 10(公司没有升级到 Swift 5 和 IOS 12/13)
应用程序代码:订阅总是发生(工作正常)
在应用程序中:didFinishLaunchingWithOptions:
Messaging.messaging().delegate = self
Messaging.messaging().subscribe(toTopic: "theTopic") { error in
print("Subscribed to LocationWakeNotify topic")
}
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.sound, .alert]) { (granted, error) in }
application.registerForRemoteNotifications()
UNUserNotificationCenter.current().delegate = self
服务器代码:
let message = {
topic: data.topic,
apns: {
payload: {
aps: {
"content-available" : 1
},
"content-id" : 1
},
headers: {
"apns-push-type" : "background",
"apns-priority" : "5"
}
}
};
我尝试了 content-available : true ,结果是一样的。
我已经尝试过使用和不使用标头,这仅在应用程序被终止并带有静默通知时才会发生,如果我发送内容(标题/正文),那么会 100% 传送到所有设备,但我需要它是静默通知。
在我看来,当我断开电源或网络或其他东西(我只是想不通)时,某些设备会松散监听器?!? 我要提到的是,我在始终有效的 XR 和失去连接的 XS Max 中的设置中找不到任何差异。
更奇怪的问题是,似乎所有设备的位置更改都在触发 (locationManage:didUpdateLocations:) 但通知委托没有被触发。 所以它甚至没有从操作系统断开应用程序。 并且通知在某些设备中一直在工作,而在其他设备中则不是......非常奇怪。
10倍
您是否注册了通知? 您可以在AppDelegate
尝试使用此代码并在didFinishLaunch
调用此函数
private func registerRemoteNotifications(for application: UIApplication) {
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
// Notifications
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { _, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
}
```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.