简体   繁体   English

当应用程序处于前台时,是否建议使用静默通知(FCM)将数据推送到移动应用程序中?

[英]Is it recommended to use silent notification(FCM) to push data into mobile apps when the app is in Foreground?

Also is there an effective way to track, by the backend server, if the app being used by a user is in the foreground?还有一种有效的方法可以通过后端服务器跟踪用户正在使用的应用程序是否在前台? What are the best practices and recommended ways in mobile app development to get the latest data as soon as possible from the backend server to mobile apps being operated in the foreground?在移动应用程序开发中,有哪些最佳实践和推荐方法可以尽快从后端服务器获取最新数据到在前台运行的移动应用程序?

Generally, for staying up to date, there are lots of solutions based on your case.通常,为了保持最新状态,根据您的情况有很多解决方案。 I'm going to divide them into two approaches:我将它们分为两种方法:

1- You pull the new data when some specific conditions meet (eg; Intervally or based on user actions). 1- 当某些特定条件满足时(例如,间隔或基于用户操作),您会提取新数据。

2- Data should be pushed to your app. 2-数据应该被推送到您的应用程序。

The first approach is quite obvious if you need to be up to date at some intervals, you can call networks APIs at intervals and fetch the latest changes.如果您需要每隔一段时间更新一次,第一种方法非常明显,您可以每隔一段时间调用网络 API 并获取最新更改。

In the second approach, In iOS operating system, while app is in foreground state, There are Silent Push Notifications and WebSockets .在第二种方法中,在 iOS 操作系统中,当应用程序在前台 state 时,有静默推送通知WebSockets

Silent push notifications is kind of push notification which can carry payloads and deliver to your app silently either your app is in background state or foreground.静默推送通知是一种推送通知,它可以携带有效负载并以静默方式传送到您的应用程序,无论您的应用程序位于后台 state 还是前台。 There is some limitations to this kind of notification, based on some conditions OS will decide to deliver push notifications to your app or not.这种通知有一些限制,根据某些条件,操作系统将决定是否向您的应用程序发送推送通知。 and also there is payload size limitation (up to 4Kb)并且还有有效载荷大小限制(高达 4Kb)
You can read more about this and its limitations in Apple Documentations您可以在Apple 文档中阅读有关此内容及其限制的更多信息

The second approach is pretty straightforward, It needs to use third-party libraries (like StarScream ) to open a socket connection and get the latest updates real-time.第二种方法非常简单,它需要使用第三方库(如StarScream )打开套接字连接并实时获取最新更新。 There is no limitations in this approach for times that server pushes data to your app or the size of payload you are receiving.对于服务器将数据推送到您的应用程序的时间或您接收的有效负载的大小,这种方法没有限制。 so you can be notified from last changes by your backend server every moment while app is in foreground and connection is alive.因此,当应用程序处于前台且连接处于活动状态时,您可以随时从后端服务器收到最新更改的通知。

Choosing between these two approaches is completely depends on your case.在这两种方法之间进行选择完全取决于您的情况。 If you should receive the update a lot of time in an hour and transferring lots of data so I recommend you the WebSocket approach, otherwise push notification will be sufficient and easier to implement.如果您应该在一小时内收到大量更新并传输大量数据,那么我建议您使用 WebSocket 方法,否则推送通知将足够且更易于实施。

暂无
暂无

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

相关问题 FCM:当应用程序处于前台状态时处理其应用程序的不同数据通知 - FCM : Handling different data notification of an android app when app is in foreground 在一加3t移动设备上杀死应用程序或从最近使用的应用程序中刷出应用程序时,Android FCM推送通知不起作用 - Android FCM Push Notification Not Working When App is being Killed or Swipe Out from Recent Apps on One plus 3t Mobile 当应用程序在前台时未收到FCM推送通知,但在应用程序在后台时收到 - FCM Push notification didn't receive when app is in foreground but receive when app in background 当App位于前台时,FCM推送通知将被替换 - FCM Push Notifications are replacing when App is in Foreground 当应用程序在前台而不是后台时,FCM通知,通知单击 - FCM notification, notification click when app is in foreground not background 当应用程序处于前台时发送推送通知 - Push notification is sent when app is in foreground 在前台在后台收到FCM通知时应用崩溃 - App Crashes when receiving FCM Notification on Foreground works on Background 应用程序在前台时无法处理 FCM 通知 - Can't handdle FCM notification when app in foreground 即使app在前台,如何让FCM显示通知? - How to let FCM display notification even when app is in foreground? 当我的应用程序前台服务被终止时,未收到 FCM 通知 - FCM Notification is not received when my app foreground service is killed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM