public void SetAlarm(AppModels.UserCondition condition) { long waitTime = condition.ReminderIntervalMillis(); if (waitTime <= 0) { return; } CancelAlarm(condition); UIApplication.SharedApplication.CancelAllLocalNotifications(); UILocalNotification notif = new UILocalNotification(); notif.FireDate = NSDate.FromTimeIntervalSinceNow(waitTime / 1000); notif.RepeatCalendar = NSCalendar.CurrentCalendar; notif.RepeatInterval = GetCalUnit(waitTime); notif.AlertAction = string.Format("{0} Reminder", condition.Condition); notif.AlertBody = string.Format("Remember to take a photo of your condition '{0}'!", condition.Condition); notif.UserInfo = NSDictionary.FromObjectAndKey(new NSString(condition.Id.ToString()), new NSString(condition.Id.ToString())); notif.ApplicationIconBadgeNumber += 1; notif.SoundName = UILocalNotification.DefaultSoundName; UIApplication.SharedApplication.ScheduleLocalNotification(notif); }
public void CancelAlarm(AppModels.UserCondition condition) { var notifs = UIApplication.SharedApplication.ScheduledLocalNotifications; foreach (UILocalNotification notif in notifs) { if (notif.UserInfo != null && notif.UserInfo.ContainsKey(new NSString(condition.Id.ToString()))) { UIApplication.SharedApplication.CancelLocalNotification(notif); break; } } }
public void CancelAlarm(AppModels.UserCondition condition) { Context context = Xamarin.Forms.Forms.Context; AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService); Intent intent = new Intent(context, this.Class); intent.PutExtra("conditionId", condition.Id); intent.PutExtra("conditionName", condition.Condition); PendingIntent pi = PendingIntent.GetBroadcast(context, condition.Id, intent, 0); am.Cancel(pi); }
public void SetAlarm(AppModels.UserCondition condition) { long now = SystemClock.ElapsedRealtime(); Context context = Forms.Context; AlarmManager am = (AlarmManager)context.GetSystemService(Context.AlarmService); Intent intent = new Intent(context, this.Class); intent.PutExtra("conditionId", condition.Id); intent.PutExtra("conditionName", condition.Condition); long waitTime = condition.ReminderIntervalMillis(); if (waitTime <= 0) { return; } PendingIntent pi = PendingIntent.GetBroadcast(context, 0, intent, 0); am.Cancel(pi); am.SetInexactRepeating(AlarmType.ElapsedRealtimeWakeup, now + waitTime, waitTime, pi); }