【问题标题】:Write appointment without user confirmation using WinRT Appointments API使用 WinRT Appointments API 在没有用户确认的情况下编写约会
【发布时间】:2014-08-14 12:22:07
【问题描述】:

我正在 Windows 8.1 中试验新的 WinRT Appointments API,基于 Microsoft 的 MSDN 网站上提供的示例:http://code.msdn.microsoft.com/windowsapps/Appointments-API-sample-2b55c76e

效果很好,我可以毫不费力地添加约会,但是当使用来自 Windows.ApplicationModel.Appointments.AppointmentManager 命名空间的方法 ShowAddAppointmentAsync 时,相关用户总是会确认,该命名空间显示约会提供者添加约会 UI。

我正在寻找一种解决方案来在默认的 Windows 8 日历中添加更大的约会集合,而不需要确认集合中的每个约会。有没有办法解决这个问题并批量插入约会?也许是 Windows Live SDK?

【问题讨论】:

标签: c# xaml windows-runtime windows-store-apps appointment


【解决方案1】:

这是不可能的,通过使用 WinRT 约会 API。 始终需要用户交互。 MS 的设计决定是某些操作需要用户交互,这就是其中之一。

正如@Ken Tucker 所说,您可以使用 windows live api 来创建约会,但这需要您的应用程序的用户在 windows live 中唱歌并获得所需的权限。

【讨论】:

    【解决方案2】:

    API在保存之前确实会提示用户,但是有一个规定可以做到这一点。

    var appointment = new Windows.ApplicationModel.Appointments.Appointment();
        appointment.details = "This is a dummy appointment";
        appointment.reminder = 15000;
        appointment.subject = "TEST APPPOINTMENT";
    
        var x = new Windows.ApplicationModel.Appointments.AppointmentManager.requestStoreAsync(Windows.ApplicationModel.Appointments.AppointmentStoreAccessType.appCalendarsReadWrite).done(function (apppointmentStore) {
            apppointmentStore.createAppointmentCalendarAsync("TEST CALENDAR").done(function (calendar) {
                calendar.saveAppointmentAsync(appointment);
            });
        })
    

    【讨论】:

      【解决方案3】:

      这是一个使用 C# 的示例

              private AppointmentCalendar currentAppCalendar;
          private AsyncLazy<AppointmentStore> lazyAppointmentStore = new AsyncLazy<AppointmentStore>(async () =>
          {
              var appStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AppCalendarsReadWrite);
              return appStore;
          });
      
          private AppointmentStore AppStore { get { return lazyAppointmentStore.Value.Result; } }
      
          public AppointmentService()
          {
          }
      
          public async Task CreateCalendar()
          {
              IReadOnlyList<AppointmentCalendar> appCalendars =
                  await AppStore.FindAppointmentCalendarsAsync(FindAppointmentCalendarsOptions.IncludeHidden);
      
              AppointmentCalendar appCalendar = null;
      
              // Apps can create multiple calendars. Here app creates only one.
              if (appCalendars.Count == 0)
              {
                  appCalendar = await AppStore.CreateAppointmentCalendarAsync(Constants.CalendarName);
              }
              else
              {
                  appCalendar = appCalendars[0];
              }
      
              appCalendar.OtherAppReadAccess = AppointmentCalendarOtherAppReadAccess.Full;
              appCalendar.OtherAppWriteAccess = AppointmentCalendarOtherAppWriteAccess.SystemOnly;
      
              // This app will show the details for the appointment. Use System to let the system show the details.
              appCalendar.SummaryCardView = AppointmentSummaryCardView.App;
      
              await appCalendar.SaveAsync();
      
              currentAppCalendar = appCalendar;
          }
      
          public async Task<bool> CreateNewAppointment(Data.Schemas.Task task)
          {
              if (null == task)
                  throw new ArgumentNullException("task");
      
              Appointment newAppointment = new Appointment();
              this.SaveAppointmentData(task, newAppointment);
      
              try
              {
                  // Show system calendar to the user to be edited
                  string appointmentId = await AppointmentManager.ShowAddAppointmentAsync(newAppointment, Windows.Foundation.Rect.Empty);                
                  return ! string.IsNullOrWhiteSpace(appointmentId);
      
                  // Just save the appointment
                  // await currentAppCalendar.SaveAppointmentAsync(newAppointment);                  
                  // return true;
              }
              catch
              {
                  return false;
              }
          }
      

      查看my post,了解有关 AsyncLazy 的更多信息。

      希望对您有所帮助。 问候。 娟路

      【讨论】:

      • 非常感谢!我一直在到处寻找 Windows 的日历功能。澄清一下,每次您想设置新约会时都必须创建一个新日历吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-21
      • 2022-10-04
      • 1970-01-01
      • 2011-06-27
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多