1

我正在尝试从 El Capitan 获取所有联系人,并且我正在使用 Contacts API 来执行此操作。这是我获取联系人的方法:

-(void)getAllContacts{
    NSError* contactError;

    //initialize the contact store
    CNContactStore* addressBook = [[CNContactStore alloc]init];

    //specify the fields I need
    NSArray * keysToFetch =@[CNContactEmailAddressesKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]];

    //establish the request with the above keys
    CNContactFetchRequest * request = [[CNContactFetchRequest alloc]initWithKeysToFetch:keysToFetch];

    //fetch all the contacts   
    BOOL success = [addressBook enumerateContactsWithFetchRequest:request error:&contactError usingBlock:^(CNContact * __nonnull contact, BOOL * __nonnull stop){
        //I'm doing nothing here to try to isolate the problem, but even if I do something here, the problem remains
    }];

    //success is always true
    //contactError is always nil
    //5 or so seconds later, I see the error output to the console
}

没什么特别的,但我每次执行此方法后,5-10 秒后都会将以下错误输出到控制台:

[Accounts] Failed to update account with identifier 72360D58-3D7H-49FC-1086-QRCIEQ8A991A0, error: Error Domain=ABAddressBookErrorDomain Code=1002 "(null)"

我没有明确尝试更新任何帐户。如果我不包括enumerateContactsWithFetchRequest调用,则不会输出错误。我已经在具有不同联系人列表的多台不同 Mac 上尝试过此操作,但我得到了同样的错误。我还在检查 CNContactStore 授权状态是否CNAuthorizationStatusAuthorized在我调用之前getAllContacts

这真是令人沮丧,我开始怀疑这可能是联系人 API 中的错误?有没有其他人看到过这个问题,或者知道可能是什么原因造成的?谢谢您的帮助!

PS。我在错误声明中更改了帐户的 ID,以防安全问题:)

4

0 回答 0