iOS local notifications ninja bug!

26 September, 2017

Recently I was working in a project that require me to show a local notification. And for the love of XCode, the app would not show an alert! I was at a loss!

Beginning with iOS 10, the iOS notification framework was revamped to unify both remote and local notifications. This threw me into a loop while trying to figure out the problem. The only thing I had to go by was an error message that popped up when adding the notification to UNUserNotificationCenter:

Adding notification request failed with error: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named" UserInfo={NSDebugDescription=connection to service named}

What a cryptic message, thanks Apple Dev team! I had a custom action setup, so the user could open a url with more info. I was adding this URL to the userInfo of the notification and here was where the bug lived! The issue was that I was adding the URL object, instead of an absolute string of the url. As soon as I changed this, everything worked.

Of course, a stackoverflow answer helped me figure this out!

Thank you for reading

Please get in touch if you have a suggestion, find an issue or want to say hello.