gpt4 book ai didi

iphone - 更改 ABRecordRef 属性

转载 作者:行者123 更新时间:2023-11-28 22:40:01 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com