IOS Overriding Local Notifications

后端 未结 2 1067
失恋的感觉
失恋的感觉 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;
    }
    

提交回复
热议问题