Local Notification



I cannot get the local notification to work, either through my own code working through the chapter, or bu loading the sample project from the downlaodable solutions. Any help/ideas would be greatly appreciated!

Thanks very much


Your not the only one, I have tried everything and for some reason the notification doesn’t seem to pop up. My code is the same as in the book and I am not running the app in the foreground so Idk why it doesn’t work.


Weird it works fine on my macbook air but not on my imac


Make sure you type this part of the code correctly.

I also couldn’t get this to work for a moment because Xcode’s code completion suggest you to complete the code with “scheduledLocalNotifications” instead of “scheduleLocalNotification” which threw me off. Hope this helps =)


I also thought my notification didn’t work but i read a few threads down that:

If the current time is 5:27:55
And you set a notification to 5:28

The notification will “fire” at 5:27:55

I waited for this, and it was true. So hopefully this helps you guys. Let me know.


For the benefit of those coming here in the future:

I’m using the Xcode 6 beta (4 currently) and targeting iOS 8, and couldn’t get my simple notification to work for the life of me. After some research and spelunking on the dev center, it appears that Local Notifications newly require user permission[1] to display notifications (this apparently wasn’t the case before iOS 8). Regardless, if you’re using the beta dev tools and targeting iOS 8, you’ll need to add a little extra code:


        UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert,
                                 categories: nil))


[[UIApplication sharedApplication] registerUserNotificationSettings:
        [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert)

Docs for these methods
There are more Types you can include, like Sounds, or Badges on the app icon.

As far as where to place this, You can follow the typical behavior of requesting this permission the first time the user launches the app: in App Delegate’s application:didFinishLaunchingWithOptions:, but I chose to call this in addReminder – the first time the user attempts to use functionality that requires a notification, I request permission to do so.

[1] “Apps that use local or push notifications must explicitly register the types of alerts that they display to users by using a UIUserNotificationSettings object. This registration process is separate from the process for registering remote notifications, and users must grant permission to deliver notifications through the requested options.” From the section about UI Kit enhancements


I, too am having trouble with this, as described above: the code works, no errors and verbatim (I think) to the book, NSLog logs to the console however no reminder appears! I am not running beta software, and testing is purely on iOS 7 simulator? I don’t have another mac to practice on to see if it works there - I have looked through the documentation for UIApplication and registering for local permissions, but haven’t found anything relevant to this exercise! Anyone had any joy?


I assume by “above” you mean “above the previous post” (since the previous post concerned was regarding iOS8).

Hard to say code “works” with iOS if it’s not doing what you expect. For example, msgs sent to nil don’t error out; they just get tossed into the bit bucket.

Have you tried pulling down from the top of the simulated iOS device (just as you would on an actual device), to check the notification center?

Can you provide some code?


gc3182, you are quite right on all accounts, I was referring to problems similar to the previous posts but one, and not iOS 8. It turns out that pulling down the notification centre did indeed reveal that the notification worked, it just didn’t show itself on cue, I assume this is a simulator or iOS setting, or some additional code is required to trigger a reminder at the time.

Thanks for the advice!


You’re quite welcome; glad you got it!


Hey, did anyone have any luck getting this to work? I am also having problems. On the new Xcode 6 ,posted the code :[[UIApplication sharedApplication] registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert) categories:nil]]; as above in the addReminder. No problem in the simulator but I am getting no notification, there is also no notification in the pull down bar. Can anyone help please? thanks!


I finally got it to work but not sure if this is the proper way to do it…
Invoking [UI Application sharedApplication] twice separately to register and schedule the notification seems a little odd?

- (IBAction)addReminder:(id)sender
    NSDate *date = self.datePicker.date;
    NSLog(@"Setting a reminder for %@", date);
    UILocalNotification *note = [[UILocalNotification alloc] init];
    note.alertBody = @"Hypnotize me!";
    note.fireDate = date;
    UIUserNotificationSettings *local = [UIUserNotificationSettings settingsForTypes:1 << 2
    [[UIApplication sharedApplication] registerUserNotificationSettings:local];
    [[UIApplication sharedApplication] scheduleLocalNotification:note];


This is how it must be done according to apple documentation

[code] UILocalNotification *notification = [[UILocalNotification alloc] init];

NSDate *date = self.datePicker.date;

notification.fireDate = date;
notification.alertBody = @"Hypnotize me!";

UIApplication *application = [UIApplication sharedApplication];

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:nil];
[application registerUserNotificationSettings];

[application scheduleLocalNotification:notification];



You have to register your notification first so that the user has chance to authorize it first. The debugger logs it on Xcode when you don’t do this which is which is how I noticed it.

3 step process:

// Define a notification settings instance to pass as argument UIUserNotificationSettings *noteSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:[NSSet set]]; //note settings object // register with notification settings the types of alerts your app needs [[UIApplication sharedApplication] registerUserNotificationSettings:noteSettings]; // schedule the notification now that we have access [[UIApplication sharedApplication] scheduleLocalNotification:note];


Meh, the notifications sometimes happen … and sometimes don’t.

I have seen one pop up in the UI exactly once. Not reproducible.

I have spliced in the code supplied, and the app asks for permission to send messages, and gets it.

Debug spew shows reminders are set, but rarely fired.

Notifications panel shows one (1) notification.

Whiskey Tango Foxtrot …

Edit: It decided to start working now. Go figure. One problem was that I didn’t know that clicking on a notification deleted it.


thx guys.
I got this issue solved by reading all your codes.

I believe how the system works has changed a bit compared with when this book is written.
Apple is constantly improving and of course, making it more complicated :laughing:


Thank you very much for your work! It is clear and beautiful! More important is that it works!


I have meet the same trouble, thank you guys, it finally works!