none
WP8.1RT中,获取联系人报错! RRS feed

  • 问题

  • 代码如下:

    我已经在【Package.appxmanifest】文件的【功能】选卡中,勾选了【联系人】,

    var contactStore = await ContactManager.RequestStoreAsync();
    var contacts = await contactStore.FindContactsAsync();// <----此行报错!

    我想获取人脉中全部的联系人时,第二行语句报以下错误:

    The operation attempted to access data outside the valid range (Exception from HRESULT: 0x8000000B)

    然后我更改为以下代码时,不报错:

    var contactStore = await ContactManager.RequestStoreAsync();
    var contacts = await contactStore.FindContactsAsync("XXXXXXXXXXX"));

    其中,【XXXXXXXXXX】是一个人脉中已存在的电话号码,

    但我想获取的是全部联系人,不知何故??

    2015年1月12日 5:45

答案

  • Hi jesse,

    >>var contacts = await contactStore.FindContactsAsync();// <----此行报错!

    我这边在模拟器上测试的代码如下:

    private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
                var contactStore = await Windows.ApplicationModel.Contacts.ContactManager.RequestStoreAsync();
                var contacts = await contactStore.FindContactsAsync();
                foreach(var contact in contacts)
                {
                    Debug.WriteLine(((Windows.ApplicationModel.Contacts.Contact)contact).DisplayName);
                }
    }

    清空人脉中的联系人之后,ContactStore.FindContactsAsync() 方法执行正常,只是联系人数量为0:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年1月13日 7:52
    版主
  • 但不知如何获取全部联系人?

    你好,

    ContactStore.FindContactsAsync 就是可以获取所有联系人的,我这边加了一些测试的联系人,可以用此方法获取到



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年1月13日 8:40
    版主

全部回复

  • Hi jesse,

    >>var contacts = await contactStore.FindContactsAsync();// <----此行报错!

    我这边在模拟器上测试的代码如下:

    private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
                var contactStore = await Windows.ApplicationModel.Contacts.ContactManager.RequestStoreAsync();
                var contacts = await contactStore.FindContactsAsync();
                foreach(var contact in contacts)
                {
                    Debug.WriteLine(((Windows.ApplicationModel.Contacts.Contact)contact).DisplayName);
                }
    }

    清空人脉中的联系人之后,ContactStore.FindContactsAsync() 方法执行正常,只是联系人数量为0:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年1月13日 7:52
    版主
  • 但不知如何获取全部联系人?
    2015年1月13日 8:31
  • 但不知如何获取全部联系人?

    你好,

    ContactStore.FindContactsAsync 就是可以获取所有联系人的,我这边加了一些测试的联系人,可以用此方法获取到



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年1月13日 8:40
    版主