简体   繁体   中英

How to properly implement Local Notifications to run daily in Xamarin.iOS

I tried implemented it UNCalendarNotificationTrigger and then tried to schedule next day's notification in WillPresentNotification . It worked until the application was in foreground but as soon as it went background it stopped scheduling for next day.

I tried using UNTimeIntervalNotificationTrigger but the problem is that it will display same notification daily however my requirement is to display different notification daily for unlimited period until user stops it from within the application or via iOS itself.

Is there some way that I can modify the title and body of the next notification to be displayed using UNTimeIntervalNotificationTrigger ?

Thanks.

Here is the sample to repeat an alarm everyday at 09:30 by using local notification in Xamarin iOS, you could have a look:

// 1
var dateComponents = new NSDateComponents();
dateComponents.Hour = 9;
dateComponents.Minute = 30;
var trigger = UNCalendarNotificationTrigger.CreateTrigger(dateComponents, true);

// 2
var content = new UNMutableNotificationContent();
content.Title = "Daily reminder";
content.Body = "Enjoy your day!";

var requestID = "request_" + id;
var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger);

// 3
UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => {
    if (err != null)
    {
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM