使用WinRT约会API编写约会,无需用户确认

本文关键字:约会 用户 确认 WinRT API 使用 | 更新日期: 2023-09-27 18:10:13

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

它工作得很好,我可以毫不费力地添加约会,但是当使用Windows.ApplicationModel.Appointments.AppointmentManager名称空间中的方法ShowAddAppointmentAsync时,总是需要用户进行确认,这显示了约会提供程序add Appointment UI。

我正在寻找一个解决方案,在默认的Windows 8日历中添加一个更大的约会集合,而不需要对集合中的每个单独的约会进行确认。是否有一种方法可以绕过这个并批量插入约会?也许是Windows Live SDK?

使用WinRT约会API编写约会,无需用户确认

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);
        });
    })

这是一个使用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;
        }
    }

查看我的帖子,了解更多关于asynlazy的信息

我希望这对你有帮助。的问候。Juanlu

这是不可能的,通过使用WinRT约会API。用户交互总是必需的。这是微软的设计决策,有些操作需要用户交互,这是其中之一。

正如@Ken Tucker所说,你可以使用windows live api来创建约会,但这需要你的应用程序的用户登录到windows live并授予它所需的权限。