简体   繁体   English

设备休眠时 FCM 推送通知重新唤醒应用程序无效

[英]FCM push notification to reawaken app not effective while device slept

I ran into a problem with my flutter app where when it's minimized or the phone is put to sleep for too long (~5+ minutes), the app stops listening to firestore changes.我的 flutter 应用程序遇到问题,当它最小化或手机休眠时间过长(约 5 分钟以上)时,该应用程序停止侦听 firestore 更改。 One solution that I came across was to send push notifications to reawaken the device.我遇到的一种解决方案是发送推送通知以重新唤醒设备。 While it seems to have fixed minimizing problem (the app now responds to changes), however it still suffers from the sleep problem.虽然它似乎已经解决了最小化问题(应用程序现在可以响应更改),但它仍然存在睡眠问题。 I noticed that the app still receives the push notifications, but the screen doesn't light up upon receiving them.我注意到该应用程序仍会收到推送通知,但屏幕不会在收到通知时亮起。 Could that be why?这可能是为什么? Is there something that I can do to force the app to connect to the inte.net?我可以做些什么来强制应用程序连接到 inte.net 吗? I'm trying to think of a solution like sending a data payload to change the data locally, but I'm not sure if that's the optimal approach (or if it would even work).我正在尝试考虑一种解决方案,例如发送数据有效负载以在本地更改数据,但我不确定这是否是最佳方法(或者它是否有效)。 I'll post my firebase cloud function for sending messages on a doc update:我将发布我的 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!",
  },
};

Is there something I'm missing?有什么我想念的吗?

Update: I think it just doesn't work because the phone is locked, once unlocked it begins to function normally.更新:我认为它只是不起作用,因为手机已锁定,一旦解锁,它就会正常开始到 function。

I think figured out why from reading here: https://developer.android.com/training/monitoring-device-state/doze-standby.html (I had trouble finding this).我想从这里读到原因: https://developer.android.com/training/monitoring-device-state/doze-standby.html (我找不到这个)。

Basically if I use the right priority settings for android and ios (priority & content_available) it will bring the app out of idle and listen for changes.基本上,如果我为 android 和 ios(优先级和 content_available)使用正确的优先级设置,它将使应用程序脱离空闲状态并监听更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有负载的 FCM 推送通知到 Android 设备 - FCM push notification without payload to Android device 如何通过令牌 ID 测试 FCM 向设备推送通知 - How to test FCM push notification to a device via a token ID FCM 推送通知 - 图片不推送 - FCM push notification - image not push FCM iOS 推送通知在应用程序终止时捕获自定义数据? - FCM iOS push notification capture custom data when app is terminated? 如何使用 Ionic 向我的应用程序的所有用户推送带有 firebase FCM 的通知? - How to push notification with firebase FCM to all users of my App with Ionic? 在 Kotlin 客户端应用程序中发送 FCM 推送通知 - Firebase 云消息传递 - Sending FCM Push Notification in Kotlin Client App - Firebase Cloud Messaging Flutter iOS 应用程序在前台时的 FCM 推送通知 - Flutter FCM push notification for iOS when app is in foreground 在 IOS 中未收到 FCM 推送通知。当应用程序在后台或终止时。我使用 FirebaseMessaging 6.0.9 Pub - Not Receive FCM Push notification in IOS.While app in background or terminate.I m use FirebaseMessaging 6.0.9 Pub 这是否可以通过后端服务器将 FCM 推送通知发送到 flutter 以安排通知,或者这可以在 flutter 应用程序中实现 - Is this possible to send FCM push Notification through backend server to flutter for scheduled the notification or this can be possible in flutter app 使用 laravel 和 FCM 发送 web 推送通知 - sending web push notification using laravel and FCM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM