Is it possible to send a “silent” push notification on iPhone (without any alert to the user)?

拟墨画扇 提交于 2019-12-06 02:28:34

问题


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).



来源:https://stackoverflow.com/questions/10123807/is-it-possible-to-send-a-silent-push-notification-on-iphone-without-any-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!