How to show the contents of notifications in the application for viewing?

I have an AppleWatch app that receives deleted notifications. I want the user to be able to open the watch app from the user notification action and view the item that the notification is about. But debugging my Notification scene in a watch application never delivers notification content to my root WKInterfaceController file and just spits out such errors in the console:

[default] - [SPRemoteInterface _interfaceControllerID:]: 2402: ComF: interfaceControllerID for controller: (null) not found (clientIdentifier = (null))

[default] - [SPRemoteInterface _interfaceControllerClientIDForControllerID:]: 2414: ComF: clientIdentifier for interfaceControllerID: (null) not found

[default] - [SPRemoteInterface didFinishHandlingActivity:]: 2292: ComF controller identifier: <-Plugin (null) (object: (null)) does not have a client identifier

WKUserNotificationInterfaceTypeCustom I use the user notification user interface or not ( WKUserNotificationInterfaceTypeCustom vs Default ), clicking a button or the notification itself does not transmit any information through my root interface controller.

I implemented handleActionWithIdentifier:forNotification: in my root WKInterfaceController , but it is never called. My extension delegate does not implement handleActionWithIdentifier:forNotification:withResponseInfo:

I tried to set my WKExtensionDelegate implementation for the UNUserNotificationCenter delegate and implement userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: and this is called, but I cannot access the root interface controller to handle the content. I get errors above.

It is noteworthy that sometimes I work when I make code changes and build and run. But if I restart the same code, it will never work - I always get the error messages above.

How should this work? It should be possible - every messenger application in the world with a clock application does it. But I cannot find a tutorial or sample code anywhere on how to reliably receive useful notification information in a subclass of WKInterfaceController .

Update: It is interesting that if I configured the extension delegate as a UNUserNotificationCenter delegate and processed userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: it works sometimes, but sometimes I get the error messages listed above and when I try to get [WKExtension sharedExtension].rootInterfaceController . nil .

+6
source share

Source: https://habr.com/ru/post/1014190/


All Articles