Android Firebase Cloud Messaging(FCM):subscribeToTopic 会自动重试吗?

Android Firebase Cloud Messaging(FCM): Will subscribeToTopic do automatic retries?(Android Firebase Cloud Messaging(FCM):subscribeToTopic 会自动重试吗?)
本文介绍了Android Firebase Cloud Messaging(FCM):subscribeToTopic 会自动重试吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在 android 客户端订阅主题,我们应该调用:

To Subscribe to a topic in an android client we should call:

FirebaseMessaging.getInstance().subscribeToTopic("news");

我想知道如果在执行该指令的那一刻互联网连接不可用会发生什么?

I want to know what happens if the internet connection is not available at moment that this instruction is executed?

当互联网连接可用时,谷歌服务会自动重试订阅吗?还是我们开发者应该处理这种情况?

Will google services automatically retry to do subscription when Internet connection become available or we developer should handle this case?

推荐答案

更新:

subscribeToTopic() 现在返回一个 Task<Void> 所以你可以附加一个 OnCompleteListener() 来检查它是否成功.

subscribeToTopic() now returns a Task<Void> so you could attach an OnCompleteListener() to check if it is successful or not.

更新:

因此,根据@DiegoGiorgini 在您之前帖子中的评论,似乎还有更多要订阅的话题:

So it seems there's more to subscribeToTopic, as per @DiegoGiorgini's comment in your previous post:

subscribeToTopic 将继续在后台重试,但它与您的应用生命周期相关(尚未与谷歌服务相关).因此,如果您的应用程序被终止,它将停止重试,直到应用程序再次打开.(该操作已存储,以便在再次启动应用程序时恢复)

subscribeToTopic will keep retry on background, but it's tied to your app lifecycle (not to google services, yet). So if your app is killed it will stop retrying until the app is open again. (the action is stored so it will be resumed when the app is started again)

我之前尝试的方式是在给定时间之后,我将杀死该应用程序并且没有再次将其拉起.

The way I was trying out before was after the given period, I will be killing the app and didn't pull it up again.

所以我试着检查一下.看起来如果发送订阅请求时设备处于离线状态,它会重试一段时间(20-30秒左右?)然后如果仍然没有连接就会停止.请求可能达到超时错误.但是由于 subscribeToTopic(),您无法通过客户端应用程序确定这一点.如果您愿意,可以发送与此相关的 功能请求.

So I've tried checking this out. It seems that if the device is offline when the request for subscription is sent, it will re-try for a period of time (20-30 seconds or so?) then will stop if still not connected. The request probably reached a time-out error. But since there is no return value for subscribeToTopic(), there is no way for you to determine this via your client app. You can send in a Feature Request if you want, pertaining to this.

但是,就目前而言,我认为您可以做的一种方法是在您的客户端应用程序中设置一个检查器,如果只有设备在线,您就会发送请求.

However, as of the moment, an approach I think that you could do is to have a checker in your client app, where if only the device is online will you send the request.

您也可以通过您的应用服务器检查它,正如我在您的上一篇文章中提到的那样.

You can also check it via your app server as I've mentioned in your previous post.

这篇关于Android Firebase Cloud Messaging(FCM):subscribeToTopic 会自动重试吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)