Push Notifications, UIUserNotificationSettings, iOS 7, and UIKit

Earlier today, while trying to set my app up to register for notifications in iOS 7 and iOS 8, I came across this exceptionally annoying bug that took me the better part of my work day to iron out. What should have been a simple process ended up keeping me bogged down pouring over the same 11 lines of code for the better part of 6 hours and so in the interest of helping out anyone else that runs across the issue I figured I’d post my solution here.

First the code snippet:

It’s a super common chunk of code that’s all over the internet from personal blogs to stackoverflow that simple allows an app to register for notifications in both iOS 7 and iOS 8. In an ideal world, the process should have been simple, just insert the code snippet, hit run, and then watch everything fall into place: but for some reason as long as the following line was present my app would crash in iOS 7 repeatedly: [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil];  with the following error: dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings .

To make an unnecessarily long story short, after consulting a coworker and working on the problem with him for a couple of hours, we discovered that the fix ended up being to manually import UIKit.framework into the app targets and set it to optional. I can honestly say I’m not100% sure why this is necessary, but I can say with all certainty that it works and I hope it saves someone else a few hours worth of work.

One thought on “Push Notifications, UIUserNotificationSettings, iOS 7, and UIKit”

  1. Dora says:

    Great goods from you, man. I’ve take into accout your stuff previous to and you’re simply too
    wonderful. I actually like what you’ve got here, really like what you are
    stating and the best way in which you say it. You are making it
    entertaining and you still take care of to stay it
    sensible. I can’t wait to learn much more from you. That is really a tremendous web site.

Leave a Reply

Your email address will not be published. Required fields are marked *