IOS Overriding Local Notifications

吃可爱长大的小学妹 提交于 2019-12-02 13:11:00

If you only use notifications for that specific action you could cancel all notifications at once using

[[UIApplication sharedApplication] cancelAllLocalNotifications];

It looks like you only have one type of local notifications in your app.

In that case you could keep it simple. Whenever you want to schedule a new one - cancel the previous one.

- (IBAction)SetButtonPressed:(id)sender {
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60];
    localNotification.alertBody = @"HEY GET UP";
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.applicationIconBadgeNumber = 
      [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!