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