Katushai
Katushai

Reputation: 1520

uilocalnotification not firing from app, but fires from simulator

here's my UILocalNotification code:

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = aNewDate;
localNotification.alertBody = alertBody;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

it fires correctly from the simulator, but not from my iphone. any suggestions?

for reference, i checked notifications in settings and my app doesnt appear there

Upvotes: 0

Views: 93

Answers (1)

Grady Player
Grady Player

Reputation: 14549

see: https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/index.html#//apple_ref/doc/uid/TP40006728-CH3-SW86

iOS 8 code: (if targeting iOS7 you will have to make sure you don't call these methods...)

scheduleLocalNotification: has a note:

Discussion: Prior to scheduling any local notifications, you must call the registerUserNotificationSettings: method to let the system know what types of alerts, if any, you plan to display to the user.

so...

    UIUserNotificationType  types = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge;

    UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

Upvotes: 1

Related Questions