警报管理器本地通知-如何取消特定通知?

时间:2019-09-17 18:15:05

标签: xamarin.forms

我正在通过警报管理器安排我的客户,以便我按时收到通知。现在,一切正常,我收到了本地通知,但是我无法取消每分钟之后就会出现的特定通知。

这是我的视图模型代码PCL 取消:

  iconDisplay(element){
    if (element.error === true) {
      return 'alert alert-danger'
    } else if ( element.status === false) {
      return 'alert alert-warning'
    } else if (element.status === true) {
      return 'alert alert-success'
    }
  }

  stateDisplay(element){
    if (element.error === true) {
      return 'Probleme'
    } else if ( element.status === false) {
      return 'Eteinte'
    } else if (element.status === true) {
      return 'Allumee'
    }
  }

用于保存警报

void Switch_Toggled()
        {

            if (NotificationONOFF == false)
            {

                MessageText = string.Empty;
                SelectedTime = DateTime.Now.TimeOfDay;
                SelectedDate = DateTime.Today;
                DependencyService.Get<ILocalNotificationService>().Cancel(Convert.ToInt32(Settings.Customerid));
            }
        }
xamarin.android中的

代码 对于Canel:

DependencyService.Get<ILocalNotificationService>().LocalNotification("Local Notification", MessageText, Convert.ToInt32(Settings.Customerid) , selectedDateTime);

我正在发送要取消的客户ID,但无法正常工作。

1 个答案:

答案 0 :(得分:0)

根据您的描述,您有xamarin.forms示例,使用“警报管理器”以重复间隔发送本地通知,例如以下示例:

https://www.c-sharpcorner.com/article/how-to-send-local-notification-with-repeat-interval-in-xamarin-forms/

有两种解决方法,但我不知道你是什么。

解决方案1:

当您运行项目并设置一个警报管理器以重复间隔发送本地通知时,此应用程序现在处于后台。

时间到了,您进入此后台应用程序,发现未选择开关,但警报仍然存在。所以您想在进入该应用时取消此警报,对吗?

如果是,建议您可以在LocalNotificationPageViewModel构造函数中调用Switch_Toggled()事件。

public LocalNotificationPageViewModel(){
        SaveCommand = new Command(() => SaveLocalNotification());
        Switch_Toggled();
    }

解决方案2:

如果您运行项目并设置一个警报管理器以重复间隔发送本地通知,并且此应用仍处于活动状态,现在时间已到,您可以取消选择开关以取消此警报,它会正常工作。