How to capture background silent Push Notifications on UAPushNotificationDelegate for iOS?

时间:2018-08-22 13:42:34

标签: ios push-notification urbanairship.com

I'm trying to implement silent Push Notifications on an iOS application and I have followed the Urban Airship Getting Started for iOS but there's not a single sample application that portraits how to implement silent push notifications that can be captured on the UAPushNotificationDelegate. I have created a test application and it's working just fine. I'm currently getting simple Push Notifications.

I have been using their Push API endpoints through CURLs command and they work perfectly.

My goal is to understand a couple of things:

  1. How to create a custom Urban Airship payload to contain a silent push notifications ({"aps":{"content-available" : 1}})
  2. How to create a custom action
  3. How to implement the registration of a custom action
  4. How to capture silent push notifications on the UAPushNotificationDelegate's func receivedBackgroundNotification(_ notificationContent: UANotificationContent, completionHandler: @escaping (UIBackgroundFetchResult) -> Swift.Void)

I would to be able to implement silent push notifications on my application and I would like to have the community help to do so. Here's a reference Apple documentation on the matter: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_updates_to_your_app_silently

And here are some questions from other UA customers with the same concern: https://support.urbanairship.com/hc/en-us/community/posts/115011296606-Differentiate-silent-notifications-from-normal-push-notification https://support.urbanairship.com/hc/en-us/community/posts/360010098392-Custom-actions-while-app-in-background https://support.urbanairship.com/hc/en-us/community/posts/360000003566-Background-notifications-working-on-some-devices-but-not-on-others

1 个答案:

答案 0 :(得分:0)

1)已回答here

2)自定义操作:

let customAction : UAAction = UAAction(block: {(args, completionHanlder) in
    // Do something with args

    completionHanlder(UAActionResult.empty())
})

3)注册动作:

UAirship.shared().actionRegistry.register(customAction, name: "custom_action_name")

4)实现委托并重写方法。如果要运行自定义操作,则需要在有效负载中将其定义为app_defined操作。