我有以下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/