代码之家  ›  专栏  ›  技术社区  ›  user2696648

将Windows Phone 7和8中的提醒设置为每隔一天关闭一次

  •  1
  • user2696648  · 技术社区  · 11 年前

    在我的应用程序中,我使用提醒服务向用户提供提醒,提示他们做某事。 我正在使用以下代码来执行此操作:

    if (date > DateTime.Now)
    {
        Reminder r = new Reminder(fileTitle);
        r.Title = fileTitle;
        r.Content = fileContent;
        r.BeginTime = date;
    
        ScheduledActionService.Add(r);
    }
    

    然而,这种情况只会发生一次。我试着设置 ExpirationTime 达到一定的值,但这每天都会重复提醒。

    有人知道如何每隔一天设置一次点火提醒吗?

    (此外,最好知道如何为一周中的某些日子设置提醒,但每隔一天的提醒是目前的主要问题。)

    2 回复  |  直到 11 年前
        1
  •  2
  •   Shawn Kendrot    11 年前

    对于您的情况,我建议存储警报应该熄灭的时间。您可以将这些信息存储在应用程序设置或文件中。当用户第一次要求安排提醒时,请继续执行您正在执行的操作,然后节省报警时间。您可能还想询问用户何时希望停止报警并保存。

    为了确保每隔一天报警一次,您需要添加 background agent 添加到您的应用程序。代理中有一个OnInvoke方法。在这种方法中,您将检查是否安排了报警。如果是,那么你就没有什么可做的了。如果不是,那么就把它安排在第二天。特工大约每30分钟开火一次,所以99%的特工开火时,警报/提醒都已经安排好了。

    以下是要放置在OnInvoke方法中的代码

    string fileTitle = "Foo";
    string fileContent = "Bar";
    var action = ScheduledActionService.Find(fileTitle);
    if (action == null)
    {
        // shouldn't be null if it was already added from the app itself.
        // should get the date the user actually wants the alarm to go off.
        DateTime date = DateTime.Now.AddSeconds(30);
        action = new Reminder(fileTitle) { Title = fileTitle, Content = fileContent, BeginTime = date };
    }
    else if (action.IsScheduled == false)
    {
        ScheduledActionService.Remove(fileTitle);
        // most likely fired today, add two days to the begin time.
        // best to also add some logic if BeginTime.Date == Today
        action.BeginTime = action.BeginTime.AddDays(2);
    }
    ScheduledActionService.Add(action);
    
        2
  •  0
  •   Mike Perrenoud    11 年前

    您需要设置 RecurrenceType RecurrenceInterval 价值不幸的是,目前没有任何自定义时间表(即每隔一天)。

    又是一次啊!微软真的在这里。