How to send silent push to iOS via Google Cloud Messaging
Asked Answered
R

3

14

How to send silent push notification to iOS application over GCM?

Silent push is notification that will not appear in notification center, but awake application to do some action in background. Google introduce new features in new GCM with possibility to send push messages to Android, Chrome and iOS.

Any idea, how to do this?

Reathareave answered 3/6, 2015 at 9:38 Comment(0)
N
10

Use the content_available (not content-available) attribute like this:

curl -X POST --header "Content-Type:application/json" --header "Authorization:key=AIzaXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" "https://android.googleapis.com/gcm/send" --data-ascii '{"data":{"xxx":"yyy"},"content_available":true,"to":"XXXXXXXXXX:YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZZZZZZZZ"}'
Nondescript answered 11/6, 2015 at 0:17 Comment(1)
@black_stallion developers.google.com/cloud-messaging/server-ref search for content_availableNondescript
T
4

From your server, you'll need to add the content-available property with a value of 1 to your aps dictionary.

You'll need to provide support for these silent notifications by adding remote-notification to UIBackgroundModes in your Info.plist file. More details here.

Twylatwyman answered 3/6, 2015 at 18:47 Comment(0)
C
0

I'm using the node-gcm npm library and the following payload works for me for iOS (for Android I'm sending a slightly different payload):

{ dryRun: false,
  data: 
   { customKey1: 'CustomValue1',
     customKey2: 'CustomValue2',
     content_available: '1',
     priority: 'high' },
  notification: 
   { title: 'My Title',
     icon: 'ic_launcher',
     body: 'My Body',
     sound: 'default',
     badge: '2' } }

Of course you'll need to ensure that your app can handle the inbound notification.

Culp answered 25/11, 2016 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.