IOS Overriding Local Notifications

后端 未结 2 1066
失恋的感觉
失恋的感觉 2021-01-29 07:50

I created a Local Notification that triggers 60 seconds when a certain button(SetButton) is clicked. My problem right now is if SetButton

相关标签:
2条回答
  • 2021-01-29 08:14

    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;
    }
    
    0 讨论(0)
  • 2021-01-29 08:27

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

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    
    0 讨论(0)
提交回复
热议问题