UILocalNotification not firing

六月ゝ 毕业季﹏ 提交于 2019-12-04 12:28:17

If you are wanting it show without a schedule (eg. when you press a button) then either use UIAlertView or add [application presentLocalNotificationNow:self.NotifyOne]; to your code.

UPDATE

Remove IBOutlet and make both declarations of UILocalNotification the same name. For example:

@interface LearnAppDelegate : NSObject <UIApplicationDelegate> {
    UIButton *_ModifyLabelButton;
    UILabel *_LabelOne;
    UILocalNotification *NotifyOne;
}

@property (nonatomic, retain) UILocalNotification *NotifyOne;

Remember to synthesize in your implementation (.m) file.

Also try this instead:

- (IBAction)changeLabel:(id)sender {
    self.LabelOne.text = @"WHAT UPPP!";
    NotifyOne = [[UILocalNotification alloc] init];
    if (NotifyOne) {
        NotifyOne.alertBody = @"Testtttttt";
        NotifyOne.alertAction = NSLocalizedString(@"Got It.", nil);
        NotifyOne.fireDate = nil;
        NotifyOne.soundName = nil;
        NotifyOne.applicationIconBadgeNumber = 0;
        [application presentLocalNotificationNow:NotifyOne];
        [NotifyOne release];
        NotifyOne = nil;
    }
}

Are you ever scheduling the alarm? Here is code I use to fire alarms.

UILocalNotification *alarm = [[UILocalNotification alloc] init];
    if (alarm) {
        alarm.fireDate = [NSDate date];
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.soundName = @"alarmsound.caf";
        alarm.alertBody = @"Test message...";       
        [[UIApplication sharedApplication] scheduleLocalNotification:alarm];
        [alarm release];
    }

A UILocalNotification isn't going to fire if you don't provide it with a fireDate and schedule it with your application instance. If you're trying to immediately present some sort of alert, perhaps you should try using UIAlertView.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!