How To Debug Notification Extensions

Notification service and content extensions can add fantastic capabilities to your app. You can extend your experience outside of your app and engage with users in whole new ways. But what happens when things go wrong?

Extensions run outside of your app. iOS loads them on-demand as plugins to the OS itself. You can't debug them like you can an app.

So how can you debug notification extensions?

Debugging a Service Extension

  1. Launch the app from Xcode or the device
  2. In Xcode, select Attach To Process or PID By Name… from the Debug menu
    attach to process by name
  3. Enter the name of your notification extension
    Xcode Debug menu, Enter Process Name
  4. Trigger a notification (by sending a push, etc.).

When the notification is delivered the service extension will launch in to the debugger.

Debugging a Content Extension

There are at least two ways. The steps shown above for a service extension also work for a content extension. The second method is more familiar but less reliable.

  1. Select the extension scheme in Xcode using the toolbar
    xcode select extension scheme
  2. In the Product menu, select Edit Scheme…
    xcode edit scheme
  3. Set the Executable to the parent application.
  4. Set a breakpoint inside the content extension.
  5. Now build and run your extension. It will launch the parent application.
  6. Trigger a notification that will cause the content extension to load.

When the notification content extension is loaded the debugger should stop on the breakpoint you set. It should – but it may not. It may also run a stale version of the host app or extension from several builds ago. When using this method it may be necessary to clean the project build folder with each new debugging session and reinstall the host app frequently. For whatever reason, the other method shown above is often more reliable.

View Debugging Content Extensions

Notification content extensions can contain complex user interfaces laid out using Autolayout. Unfortunately Xcode's View Debugging will not show the custom user interface of your notification.

The commercial view debugging tool Reveal, however, will. Integrating and using Reveal is simple and it does provide insights that Xcode does not. If you find yourself struggling with the interface of a content extension it is worth giving Reveal a try.

Logging And Activity Tracing

Because it can be difficult, cumbersome, or impossible to troubleshoot some notification extensions issues using a debugger it can be a great opportunity to learn the new(ish) Universal Logging and Activity Tracing APIs. Both of these are easy to use and make troubleshooting extensions much easier.

Unless you are using Swift. Activity Tracing is still not available to Swift as of this writing.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.