Мы можем использовать AlarmManager.Cancel
и UIApplication.SharedApplication.CancelLocalNotification
, чтобы остановить локальные уведомления по расписанию.
iOS:
void CancleScheduleNotification()
{
UILocalNotification[] localNotifications= UIApplication.SharedApplication.ScheduledLocalNotifications;
//Traverse this array to get the UILocalNotification we want according to the key
foreach (var localNotification in localNotifications)
{
if(localNotification.UserInfo.ObjectForKey(new NSString("key")).ToString() == "value")
{
UIApplication.SharedApplication.CancelLocalNotification(localNotification);
}
}
}
Android:
void CancleScheduleNotification()
{
AlarmManager am = (AlarmManager)GetSystemService(Context.AlarmService);
Intent intent = new Intent("LILY_TEST_INTENT");
intent.SetClass(this, LilyReceiver.class);
intent.SetData(Android.Net.Uri.Parse("content://calendar/calendar_alerts/1"));
PendingIntent sender = PendingIntent.GetBroadcast(this, 0, intent, PendingIntentFlags.NoCreate);
if (sender != null){
Log.Info("lily","cancel alarm");
am.Cancel(sender);
}else{
Log.Info("lily","sender == null");
}
}