【发布时间】:2016-03-03 06:06:02
【问题描述】:
当应用不活动时,我们可以在推送通知发送或关闭时从客户端进行服务调用吗?
APNS 是否还提供任何有关通知是否在个人级别传递的信息,是否有任何 API 可以用来查询传递状态报告?
【问题讨论】:
标签: ios objective-c push-notification apple-push-notifications
当应用不活动时,我们可以在推送通知发送或关闭时从客户端进行服务调用吗?
APNS 是否还提供任何有关通知是否在个人级别传递的信息,是否有任何 API 可以用来查询传递状态报告?
【问题讨论】:
标签: ios objective-c push-notification apple-push-notifications
是的,如果您将content-available 标志发送到aps 字典中的1,您可以检测到远程通知的传递。如果设置了key,就会调用AppDelegate的application:didReceiveRemoteNotification:fetchCompletionHandler:方法。
此外,从 iOS 10 开始,您还可以检测远程通知的消失。为此,您需要实施 UserNotifications 框架。
您需要执行以下步骤:
使用 iOS 10 API 注册远程通知的类别。
您需要检查[[UNUserNotificaionCenter currentNotificationCenter] setNotificationCategories] 方法是否相同。见https://developer.apple.com/documentation/usernotifications/unusernotificationcenter
iOS 10 引入了一个名为 UNNotificationCategory 的新类,用于封装类别实例。您需要在类别实例上设置CustomDismissAction 才能接收解除回调。
见https://developer.apple.com/documentation/usernotifications/unnotificationcategory
userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:方法的实现实现UNUserNotificationCenterDelegate协议。如果您执行上述步骤,此方法将接收对解除操作的回调。见https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate
将您的委托设置为 UserNotificationCenter - [[UNUserNotificaionCenter currentNotificationCenter].delegate = your_delegate_implementation
CustomDismissAction 属性设置类别。 {
"aps": {
"alert": "joetheman",
"sound": "default",
"category": "my-custom-dismiss-action-category",
"content-available":1
},
"message": "Some custom message for your app",
"id": 1234
}
【讨论】:
customDismissAction 仅用于解雇目的,但这是不正确的。这只是拥有类别的众多目的之一。类别可用于 1. 分组操作 2. 添加占位符以防用户隐藏预览 3. 通过类别进行其他调整 选项,例如您的答案
是的,当应用不活动时收到通知时,您可以从 ios 应用拨打服务电话。这样做:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
<#code#>
}
是的,您可以在推送通知负载中添加额外的键值对。
{
"aps": {
"alert": "joetheman",
"sound": "default"
},
"message": "Some custom message for your app",
"id": 1234
}
【讨论】: