I want to implement push notifications on both Android and iOS with Google Cloud Messaging.
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.
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?
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.
Can I get this kind of control on iOS?
You have to disable the content_available
flag to false
, so that it works on Ios as expected and provide full control on android,
Source:- I have worked on Push Notification on both android and IOS recently
Answer:
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
.
Tags: androidandroid, ios