0

I have an app, that supports local and push notifications. Those notifications include a url. Once the user opens the notification, the web page for the url should be loaded. This works.

However the same notification can also be received on the watch. When the user selects the notification and hands it off to the phone, the url should also be opened.

I implemented the following method:

public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool

It is called on handoff. Unfortunately the created userActivity does not contain the notification payload. Instead the userInfo only includes the notificationIdentifier. It looks like this:

  ▿ Optional<Dictionary<AnyHashable, Any>>
    ▿ some : 1 element
      ▿ 0 : 2 elements
        ▿ key : AnyHashable("NotificationIdentifier")
          - value : "NotificationIdentifier"
        - value : 0F99DF81-C721-4A56-850A-13CF74A85547

How can I retrieve the notification payload?

gebirgsbärbel
  • 2,327
  • 1
  • 22
  • 38
  • Using `UNUserNotificationCenter. getDeliveredNotifications(completionHandler:)` you should be able to get all delivered notifications and filter out the one that has the identifier you are interested in. – Dávid Pásztor Aug 10 '17 at 15:15
  • the problem is, that this list is nil, as the notification is sent to the watch and the list on the device is empty. :( – gebirgsbärbel Aug 10 '17 at 15:17
  • Then you should include the URL in the `userActivity`'s `userInfo` property, which you can access in `application(continue..)` – Dávid Pásztor Aug 10 '17 at 15:22
  • The notification is a standard push notification from apple. The url is in the `userInfo` of the `notification`. However, I do not know, how to get this information into the `userInfo` from the `userActivity` without having a watch app. – gebirgsbärbel Aug 10 '17 at 15:28
  • So you don't have a Watch app, I see. In this case, I can't see any other way to get more information from the notification if you can't find it in the notification centre. Btw, why don't you send the push notification to the phone? With the correct user settings, the notification will be mirrored to the watch, but you won't have to send the URL to the phone, since you will be able to access the notification on the phone itself. – Dávid Pásztor Aug 10 '17 at 15:57
  • Hi David, it is sent to the phone. However some users tried to tap it on the watch and hand over to the app. This currently leads to an error message and I had hoped, I could avoid this. Thank you very much for your help :) – gebirgsbärbel Aug 10 '17 at 16:40

0 Answers0