User382
User382

Reputation: 874

Stop iOS local notifications at particular time

My app using User Notification framework to schedule local notifications every 30 minutes. I set a trigger

  var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(60 * 30, true); 

However, i would like to stop these notifications after certain time lets say 9.00 PM. How do i do it?

Upvotes: 0

Views: 536

Answers (1)

miOS
miOS

Reputation: 1377

There are 3 opitios to remove local notifications.

1. When app is in foreground:- If app is in foreground, check the local device time and remove all pending local notifications.

UNUserNotificationCenter.Current.RemoveAllPendingNotificationRequests();

2. If app is in background: You cannot execute a code at certain time when the App is in background. There are two approaches to remove local notification at certain time. However, it's the OS who decide whether the callback methods should call or not depending upon resources available, battery percentage, is device is on charging etc.

a. Background Fetch - Enable background fetch capability, which will call callback method after specific time when the device is in background. Again, OS will decide when to call depending upon uses of app.

//Fetch interval 
UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);


//Call back method
    public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
        {
           // Code of removing local notifications
        }

b. Using silent notification: When app received silent remote notification, remote notification received callback method called without sound and alert. You can executes code for remove local notification.

Upvotes: 1

Related Questions