远程关闭 iOS 推送通知 [英] Dismissing iOS push notifications remotely

查看:44
本文介绍了远程关闭 iOS 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 版 Gmail 应用能够在应用未运行时接收推送通知(与大多数电子邮件应用一样).

The Gmail app for iOS is able to receive push notifications while the app is not running (as most email apps do).

但是,当用户收件箱的未读计数为零时,它也可以清除设备中的所有 Gmail 推送通知,即使应用未运行.

However, it is also able to clear all Gmail push notifications from the device when the unread count of the user's Inbox becomes zero, even if the app is not running.

这是一个示例序列:1. 在您的 Gmail 帐户中收到一封新电子邮件.2. iOS 设备显示新消息通知.3. 转到 Gmail 网站并打开邮件(将邮件标记为已读").4.iOS设备上的通知被关闭.

Here is an example sequence: 1. Receive a new email in your Gmail account. 2. The iOS device displays a notification for the new message. 3. Go to the Gmail website and open the message (marking the message as "read"). 4. The notification on the iOS device is dismissed.

注意:[[UIApplication sharedApplication]cheduledLocalNotifications] 仅提供本地通知,即那些在 iOS 应用本身内创建的通知.

Note: [[UIApplication sharedApplication] scheduledLocalNotifications] only provides local notifications, i.e. those that were created within the iOS app itself.

就 Apple 的 APNS 文档而言 描述,没有办法 将应用远程启动到后台,并且无法关闭远程通知.

As far as Apple's documentation for APNS describes, there is no way to remotely launch an app into the background, and there is no way to dismiss a remote notification.

那么,Gmail iOS 应用如何实现这一目标?

So, how does the Gmail iOS app make this work?

推荐答案

通过使用 Parse 推送此有效负载,我还能够清除所有推送通知.我猜只要你提供 content-availablebadge,你应该能够做同样的事情.我不必在 AppDelegate 中编写任何其他代码,但我确实必须在项目目标 capabilities 中打开推送通知.

I was able to clear all of my push notifications as well by pushing this payload, using Parse. I'm guessing as long as you supply content-available and badge, you should be able to do the same. I didn't have to write any other code in the AppDelegate, but I did have to turn on push notifications in the projects target capabilities.

curl -X POST \
-H "X-Parse-Application-Id: xxxxxxxxxxx" \
-H "X-Parse-REST-API-Key: xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
       "data": {
         "content-available": "1",
         "badge":"0",
         "sound":""
       },
       "where": {"something":"something_else"}
     }' \
https://api.parse.com/1/push

这篇关于远程关闭 iOS 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆