ios 什么是静默推送通知?设备什么时候收到?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36694963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is Silent Push Notification? When does the device receive it?
提问by Suhas Patil
I want to clear my local notification in notification tray. For this to be implemented, I am thinking to use the silent push notification. So I want to confirm when the device receives it and which things I can do with it?
我想清除通知托盘中的本地通知。为了实现这一点,我正在考虑使用静默推送通知。所以我想确认设备何时收到它以及我可以用它做什么?
回答by Pierre Oleo
They can be used to inform the application of new content without having the user informed. Instead of displaying a notification alert, the application will be awakened in background (iOS does not automatically launch your app if the user has force-quit it) and application:didReceiveRemoteNotification:fetchCompletionHandler:will be called. You then have the opportunity to process any information transparently for the user :
它们可用于在不通知用户的情况下通知应用程序新内容。应用程序将在后台唤醒而不是显示通知警报(如果用户强制退出,iOS 不会自动启动您的应用程序)并且 application:didReceiveRemoteNotification:fetchCompletionHandler:将被调用。然后,您有机会为用户透明地处理任何信息:
- Download some content
- Synchronize some elements,
- Inform the user directly within the application when he opens it back
- 下载一些内容
- 同步一些元素,
- 当用户打开它时直接在应用程序中通知用户
Note that your time is limited to 30s.
请注意,您的时间限制为 30 秒。
To configure silent notifications
配置静默通知
To support silent remote notifications, add the remote-notification value to the UIBackgroundModes array in your Info.plist file. To learn more about this array, see UIBackgroundModes.
要支持静默远程通知,请将 remote-notification 值添加到 Info.plist 文件中的 UIBackgroundModes 数组。要了解有关此数组的更多信息,请参阅 UIBackgroundModes。
<key>UIBackgroundModes</key>
<array>
????<string>remote-notification</string>
</array>
Configuring a Silent Notification
The aps dictionary can also contain the content-available property. The content- available property with a value of 1 lets the remote notification act as a silent notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren't told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.
For a silent notification, take care to ensure there is no alert, sound, or badge payload in the aps dictionary. If you don't follow this guidance, the incorrectly-configured notification might be throttled and not delivered to the app in the background, and instead of being silent is displayed to the user
配置静默通知
aps 字典还可以包含 content-available 属性。值为 1 的 content-available 属性让远程通知充当静默通知。当静默通知到达时,iOS 会在后台唤醒您的应用程序,以便您可以从服务器获取新数据或进行后台信息处理。用户不会被告知由无提示通知产生的新信息或更改信息,但他们可以在下次打开您的应用时了解这些信息。
对于无声通知,请注意确保 aps 字典中没有警报、声音或徽章负载。如果您不遵循此指南,则错误配置的通知可能会受到限制并且不会在后台传递到应用程序,而是会向用户显示而不是静默
回答by Arpit
When you send a silent push notification and if app is suspended then the system wakes up or launches your app and puts it into the background running state before calling the method but if the app is killed by user manually then it will not wakeup.
当您发送静默推送通知并且如果应用程序被挂起时,系统会在调用该方法之前唤醒或启动您的应用程序并将其置于后台运行状态,但如果应用程序被用户手动杀死,则它不会被唤醒。
application:didReceiveRemoteNotification:fetchCompletionHandler:
应用程序:didReceiveRemoteNotification:fetchCompletionHandler:
This method is called when you send a silent push notification and your app has up to 30 seconds of wall-clock time to perform the download or any other kind of operation and call the specified completion handler block. If the handler is not called in time, your app will be suspended.
当您发送无提示推送通知并且您的应用程序有最多 30 秒的挂钟时间来执行下载或任何其他类型的操作并调用指定的完成处理程序块时,将调用此方法。如果没有及时调用处理程序,您的应用程序将被挂起。
If you want to send a silent push notification then your notification payload should be like this :
如果您想发送静默推送通知,那么您的通知负载应该是这样的:
{
"aps" = {
"content-available" : 1,
"sound" : ""
};
// You can add custom key-value pair here...
}