我有以下cpde:
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, ABRecordGetRecordID(self.recordRef_));
CFErrorRef error = NULL;
if ([self.nameTextField_.text isNotNull]){
NSArray *nameStringArray = [self.nameTextField_.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
ABRecordSetValue(person, kABPersonFirstNameProperty, (__bridge CFTypeRef)([nameStringArray objectAtIndex:0]), NULL);
if ([nameStringArray count] > 1){
ABRecordSetValue(person, kABPersonLastNameProperty, (__bridge CFTypeRef)([nameStringArray lastObject]), &error);
}
}
但是,在这段代码之后,它给了我这个错误:
Error Domain=ABAddressBookErrorDomain Code=0 "The operation couldn’t be completed. (ABAddressBookErrorDomain error 0.)"
知道为什么会这样吗?
最佳答案
该错误消息似乎几乎没有用,但是由于您其余的代码看起来都是有效的,因此我猜测您的应用程序尚未得到用户的授权以访问通讯簿数据库。在尝试访问地址簿之前,请使用以下代码检查您的授权状态:
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// We're good to go
} else {
// Hasn't been authorized by the user
// You can check the exact authorization status for more information on the
// exact reason why you can't access the Address Book (e.g. denied, restricted, etc.)
}
关于iphone - 更改ABRecordRef属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14804279/