[英]FCM push notification to reawaken app not effective while device slept
我的 flutter 應用程序遇到問題,當它最小化或手機休眠時間過長(約 5 分鍾以上)時,該應用程序停止偵聽 firestore 更改。 我遇到的一種解決方案是發送推送通知以重新喚醒設備。 雖然它似乎已經解決了最小化問題(應用程序現在可以響應更改),但它仍然存在睡眠問題。 我注意到該應用程序仍會收到推送通知,但屏幕不會在收到通知時亮起。 這可能是為什么? 我可以做些什么來強制應用程序連接到 inte.net 嗎? 我正在嘗試考慮一種解決方案,例如發送數據有效負載以在本地更改數據,但我不確定這是否是最佳方法(或者它是否有效)。 我將發布我的 firebase 雲 function 以發送有關文檔更新的消息:
exports.sendLobbyNotificationTest = functions.firestore
.document("Lobbies/{lobbyCode}")
.onUpdate((change) => {
console.log("Checking for need of push notification...");
// const oldValue = change.before.data() || {};
const newValue = change.after.data() || {};
if (newValue.pushNotification == true) {
console.log("Found a push notification request for: ",
newValue.lobbyCode, "!");
// Set lobby back to false
admin.firestore().collection("Lobbies")
.doc(newValue.lobbyCode).update({
pushNotification: false,
});
return admin.messaging().sendToTopic(newValue.lobbyCode, message)
.then((result) => {
console.log("Message sent successfully: ", result);
// usersRef.where("lobbyCode", "==", newValue.lobbyCode).get()
// .then(function(querySnapshot) {
// querySnapshot.forEach(function(doc){
// })
// })
}).catch((err) => {
console.error("Error sending message: ", err);
});
}
console.log("No message needs to be sent!");
// return dummy value to prevent error
return 0;
});
const message = {
notification: {
title: "Bzzzt!",
body: "You've been buzzed!",
},
};
有什么我想念的嗎?
更新:我認為它只是不起作用,因為手機已鎖定,一旦解鎖,它就會正常開始到 function。
我想從這里讀到原因: https://developer.android.com/training/monitoring-device-state/doze-standby.html (我找不到這個)。
基本上,如果我為 android 和 ios(優先級和 content_available)使用正確的優先級設置,它將使應用程序脫離空閑狀態並監聽更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.