使pubnub订阅处于最佳服务状态 [英] Is leaving a pubnub subscription open in a service optimal

查看:83
本文介绍了使pubnub订阅处于最佳服务状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以选择使用GCM进行推送通知,但是我决定让pubnub订阅在后台运行的服务中保持打开状态.

I have a choice to either use GCM for push notifications but I have decided to leave a pubnub subscription opened in a running service in the background.

这是一个聊天界面,每个用户都在后台将其频道保持打开状态,并且仅在打开聊天屏幕时才发布到目标频道.

It's a chat interface where every user leaves his channel open in the background and only publish to the destination channel when the chat screen is opened.

这样做有什么弊端,如果这不是最佳方法,我该怎么做才能对其进行优化?

What are the drawbacks to this and if this is not the optimal way, what can I do to optimize it?

推荐答案

PubNub Android后台服务与GCM

由于感觉到的后台服务电池使用情况,对于最终用户而言,使用GCM可能是一种更可接受的方法.使用PubNub,您只需

PubNub Android Background Service vs GCM

Using GCM might be a more acceptable way for end users due to the perceived battery usage of background services. And with PubNub, you just publish the message including the GCM push payload and the device will receive the realtime message when app is active and the push notification when the app is not active (or not running).

但是也许您需要在后台保持与PubNub的连接.现在,您必须确定是否在Android服务上阅读.我假设您(@olayinka)知道这一点,但只是将其放置在此处,以便更广泛的读者阅读这篇文章.

But perhaps you have a requirement to stay connected to PubNub in the background. Now you have to decide whether you want this service to be started when the device is powered on (even if the app is never started) or only start service when the app is first started. Either way, read up on Android Services. I assume you (@olayinka) know this but just putting this here for the wider audience reading this post.

对于 Android 6 (不是5),您必须通知最终用户您正在启动一项服务,该服务将在后台运行,并且用户必须允许该服务.解决此问题的唯一方法是将该应用列入白名单.

With Android 6 (not 5), you have to notify the end user that you are starting a service to run in background and the user has to allow it. Only way to get around this is whitelisting the app.

有三种将应用列入白名单的方式,所有这些方式都需要用户交互.您可以阅读有关打ze模式和应用白名单的完整文档,但以下是亮点:

There are three ways to whitelist the app and all of them require user interaction. You can read the full docs about doze mode and app whitelisting but here are the highlights:

  1. 用户可以在设置>中手动配置白名单.电池>电池优化.

拥有REQUEST_IGNORE_BATTERY_OPTIMIZATIONS权限的应用程序可以触发系统对话框,使用户可以直接将应用程序添加到白名单中,而无需进行设置.该应用会触发ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS意图来触发对话框.这是正常权限:请求该应用的应用将始终被授予该权限,而无需用户批准或查看它.

An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog to let the user add the app to the whitelist directly, without going to settings. The app fires a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog. This is a normal permission: an app requesting it will always be granted the permission, without the user needing to approve or see it.

拥有 REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 权限的应用程序可以触发系统对话框,使用户可以直接将应用程序添加到白名单中,而无需进行设置.该应用会触发 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 意图来触发对话框.这是正常权限:请求该应用的应用将始终被授予该权限,而无需用户批准或查看它.注意:据某些博客报道,应用程序已从Google Play商店中删除,并在尝试执行此操作时受到审查.

An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog to let the user add the app to the whitelist directly, without going to settings. The app fires a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog. This is a normal permission: an app requesting it will always be granted the permission, without the user needing to approve or see it. NOTE: it has been reported in some blogs that apps were removed from Google Play store and put under scrutiny when they tried doing this.

需要PARTIAL_WAKE_LOCK来保持所有Android版本在后台接收消息,以防止设备 do睡.

PARTIAL_WAKE_LOCK is required to keep receiving messages in background for all Android versions to prevent device from dozing.

这篇关于使pubnub订阅处于最佳服务状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆