[英]Firebase Messaging not waking up iOS device when receiving push notifs
我正在使用 FCM 向單個 iOS 設備發送推送通知,在對 Firebase Cloud Functions 的 http 請求時觸發。 遵循 FCM 和 APNs 文檔后,當應用程序在后台運行時,一切正常。 我在所有情況下都成功收到通知。
唯一的問題:推送通知沒有從睡眠狀態點亮我的鎖屏。 我仍然收到推送通知,當我按下主頁按鈕手動喚醒設備時可以看到它。 但是通知本身不會喚醒我的設備。
如何復制
我打開了“后台模式”功能 > 選擇了“遠程通知”和“后台獲取”。 我的部署目標是 10.0。 我的應用程序允許鎖定屏幕通知。
(對類似問題的大多數答案都是“打開后台模式”或“將內容可用設置為 1”,這兩個我都做過。)
我將有效負載發送到 APN 的雲功能:
exports.pushMatchNotif = functions.https.onRequest((req, res) => {
let receiverToken = req.receiverToken
var msg = {
'apns': {
'header': {
'apns-priority': '10'
},
'payload': {
'aps': {
'alert': {
'title': 'Hi',
'body': 'Hello',
},
'badge': 2,
'sound': 'default'
'content-available': 1
}
}
},
'token': receiverToken
};
admin.messaging().send(msg)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
let json = {"Response": response}
res.send(json)
})
.catch((error) => {
console.log('Error sending message:', error);
let json = {"Error": error}
res.send(json)
});
})
我的 didFinishLaunchingWithOptions 方法:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge , .sound]) {
(granted, error) in
print("granted is \(granted)")
}
application.registerForRemoteNotifications()
return true
}
我的 didReceiveRegistrationToken 方法(FCM 委托方法):
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase deviced token: \(fcmToken)")
}
我的 didReceiveRemoteNotification 方法:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
}
我錯過了什么?
我有同樣的問題。 原來我啟用了“請勿打擾”模式。 禁用它解決了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.