How to avoid this error: “Took too long to show cu

2020-08-16 03:19发布

问题:

Having issues testing out the custom long look notification on the apple watch simulator. The debugger log this error:

WatchKit Extension[5230:156324] Took too long to show custom notification. Falling back to static.

How to resolve this issue?

回答1:

I had exactly this problem with the default code set up by Xcode. I didn't do any operations inside didReceiveRemoteNotification, but the error still occured.

Turns out the reason it failed was that my WKUserNotificationInterfaceController subclass was not connected to the Dynamic interface Controller in my storyboard file.

Solution:

  1. Go to the storyboard file for your watchkit app.
  2. Click on your Dynamic Interface controller
  3. Click the identity inspector (middle tab in the right pane)
  4. In the Class field, select your WKUserNotificationInterfaceController subclass (xcode had named mine NotificationController)
  5. Voilà!



回答2:

I had the same issue before. Inside didReceiveRemoteNotification, are you calling completionHandler(WKUserNotificationInterfaceTypeCustom); ? Also, what are you doing inside that function? If takes too much time, it will show by default the static notification:

"Use the static notification interface to define a simple version of your custom notification interface. The purpose of a static interface is to provide a fallback interface in the event that your WatchKit extension is unable to configure the dynamic interface in a timely manner"



回答3:

Try giving your custom class name as NotificationController. Xcode take it as WKUserNotificationcontroller. It worked for me.



回答4:

This will happen if you take too long in your handler to setup. If it takes too long, the watch will default to the static notification.

Be sure you are calling the correct completion block:

completionHandler(WKUserNotificationInterfaceTypeCustom);

When calling the completion handler block, if you want WatchKit to display your static interface instead, specify the WKUserNotificationInterfaceTypeDefault constant.

Reference: https://developer.apple.com/library/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/CustomzingthePushNotificationInterface.html



回答5:

In my case the problem was that the created WatchKit Extension was configured as Swift code, while my entire project was in Objective-C.

The Dynamic Interface never show up, always switching to the Static one printing the error of this post in the console. Once I changed the WatchKit Extension to Objective-C everything worked perfectly.



回答6:

If you use a real watch, try turn off "Wrist Detection" in "Watch" -> "General".