Fix Your Notifications on iOS 10.3

TL;DR — Jump to the code sample section :)

Ever since iOS version 10.2, I’ve been getting unusual behaviors from my push notifications. In some cases, the notification actions tied to some categories stopped showing on push and local notifications. Being the lazy developer that I am, I marked it as an iOS bug and went on with my day.

Once iOS 10.3 became available, I immediately updated my iPhone 6+ with it. Working on one of our apps at Neura, I noticed notification actions were not working anymore. I had to dive in and understand what went wrong!

If it ain’t broken, don’t try to fix it.

Developers love that phrase. But don’t get confused, deprecated APIs can become obsolete without warning. You should always pay attention to what’s happening with the API you are using. And with the adoption rate of new iOS versions, for me to keep using an API that was deprecated two versions ago (iOS 8.0) was irresponsible to say the least. To get my push notifications working, I had to replace the deprecated APIs.

Here’s How I Replaced the Old APIs

This will continue with the code presented in my previous post. A simple iOS app that displays notifications according to your medication adherence needs.

1. Use the new UNNotificationCategory instead of the old UIMutableUserNotificationCategory

2. Update your registration to notifications

3. Present the relevant notification

In (3) you’ll notice the different triggers in the new UNNotificationRequest. I implemented the two relevant to my code, UNTimeIntervalNotificationTrigger and UNCalendarNotificationTrigger. Notice that timezone for the relevant device is set in the dateComponents and not in the notification itself as it used to be with notification.timeZone.

The latest code is already merged to the master branch in GitHub.

Have fun!


Follow Neura’s new publication Contextual Wisdom to stay updated on the latest in AI, mobile apps, and IoT.