Is it possible to send a “silent” push notificatio

2019-04-08 16:24发布

问题:

I need to do it on a chat app to notice the client that there is new data to fetch from the server.

I know that technically it is possible with an empty payload (at least on ios 5 device it worked), but can Apple see it as abuse of service or is it OK to do it?

And is it technically possible on ios 4 device?

回答1:

Yes, increment only badge number, dont send sound and alert, So, there will be one badge on the App icon.

So, here unknowingly the badge number will be incremented to show that something has been recieved when user watches the app icon.

But your device won't recive alert or empty payload and won't recieve sound also because you asked for “silent” push notification on iPhone

and while configuring in AppDelegate, configure only badges

 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge];

Hope this will be helpful for you



回答2:

You need to build the payload like this:

String payload = 
'{
    "aps":{
        "content-available": 1 
    }, 
    "data_id": 5, 
    "additional_data": ["some", "data"]
}'

In aps put the apple variales needed to make the push notification display a text, sound, badge... or just content-available to make it silent. Then, out of 'aps{...}' and separated with ',' put your custom fields to send the needed information for the download.



回答3:

If you don't want the badge number to increase you could also try sending a sound notification which plays a silent sound file. (Unfortunately, I don't know if this is ok for Apple).