在Android和iOS上使用GCM,而无需通知有效内容 [英] Using GCM on both Android and iOS without a notification payload
问题描述
我想通过Google Cloud Messaging在Android和iOS上实施推送通知。
I want to implement push notifications on both Android and iOS with Google Cloud Messaging.
我不想使用通知
键,因为Android的行为并不理想。在Android上,我更喜欢我的接收器总是通过 data
有效载荷触发,我可以自己构造 Notification
使用 NotificationCompat
。例如,如果您在Android上使用通知
有效载荷,则无法控制通知样式。
I don't want to use the notification
key in my payload because the Android behavior is not ideal. On Android, I would prefer my receiver to always get triggered with the data
payload, and I can construct the Notification
myself using NotificationCompat
. If you use the notification
payload on Android, you have no control over the notification style, for example.
然而, ,如果我只发送一个数据
有效载荷,我认为我的iOS应用程序如果它是后台 - 死亡,从设备重启以来从未启动等等,我不会收到推送。对于GCM,哪个 content_available
标志可能触发推送?
However, if I only send a data
payload, I think my iOS app will not receive the push if it is backgrounded - killed, never launched since device restart, etc. I think there's that content_available
flag for GCM which may trigger the push anyway?
我是否可以在iOS上复制总是在通知后执行我的应用内代码的Android行为?我会很好地根据GCM data
有效载荷构建我自己的iOS通知,也许使用类似于 UILocalNotification
,但从我读的内容来看,iOS需要存在通知
有效载荷以确保推送总是被用户接收。
Am I, on iOS, able to duplicate the Android behavior of always having my in-app code execute upon notification? I'd be fine constructing my own iOS notification based on the GCM data
payload, and perhaps using something like a UILocalNotification
, but from what I'm reading, iOS is requiring the notification
payload to exist to make sure the push is always received by the user.
我可以在iOS上获得这种控制吗?
Can I get this kind of control on iOS?
推荐答案
从我的研究中,无法避免使用通知
有效负载。但是,如果不是创建扩展 GcmListenerService $
的
MyGcmListenerService
,则可以摆脱自动创建通知的默认Android行为。 c $ c>,你可以创建自己的 GcmListenerService
,并且可以扩展原来的 Service
。
From my research, it seems that you can't avoid using the notification
payload. However, you can get rid of the default Android behavior of auto-creating a notification, if, instead of creating a MyGcmListenerService
that extends GcmListenerService
, you create your own GcmListenerService
and extend plain old Service
.
这篇关于在Android和iOS上使用GCM,而无需通知有效内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!