[英]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.