推送通知传递和解除回叫

时间:2016-03-03 06:06:02

标签: ios objective-c push-notification apple-push-notifications

当推送通知发送时,我们可以从客户端进行服务呼叫吗?当应用程序未处于活动状态时,我们可以将其解除吗?

APNS也会提供有关通知是否在个人层面上发送的任何信息,是否有任何API可用于查询交付状态报告?

2 个答案:

答案 0 :(得分:2)

是的,如果您在content-available词典中将1标记发送到aps,则可以检测到远程通知的传送。如果设置了密钥,则会调用AppDelegate的application:didReceiveRemoteNotification:fetchCompletionHandler:方法。

此外,从iOS 10开始,您还可以检测到远程通知的解除。为此,您需要实现UserNotifications Framework。

您需要执行以下相同步骤:

  1. 使用iOS 10 API注册远程通知的类别。 您需要检查[[UNUserNotificaionCenter currentNotificationCenter] setNotificationCategories]方法。请参阅https://developer.apple.com/documentation/usernotifications/unusernotificationcenter

  2. iOS 10引入了一个名为UNNotificationCategory的新类,用于封装类别实例。您需要在类别实例上设置CustomDismissAction才能接收解雇回调。

  3. 请参阅https://developer.apple.com/documentation/usernotifications/unnotificationcategory

    1. 使用UNUserNotificationCenterDelegate方法实现userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:协议。如果您执行上述步骤,此方法将收到对解除操作的回调。
    2. 请参阅https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate

      将您的代理人设置为UserNotificationCenter - [[UNUserNotificaionCenter currentNotificationCenter].delegate = your_delegate_implementation

      1. 在有效负载中设置具有CustomDismissAction属性的类别。 { "aps": { "alert": "joetheman", "sound": "default", "category": "my-custom-dismiss-action-category", "content-available":1 }, "message": "Some custom message for your app", "id": 1234 }

答案 1 :(得分:0)

是的,当应用程序未处于活动状态时,您可以在收到通知时从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
}
相关问题