gpt4 book ai didi

ios - 如何从 AddressBook 中获取联系人并将其存储在 iOS 7 中的数组中?

转载 作者:行者123 更新时间:2023-11-29 12:48:08 24 4
gpt4 key购买 nike

我正在尝试从地址簿中获取联系人,然后将其存储在数组中。我无法执行此操作。我检查了有关堆栈溢出的各种帖子,我正在编写相同的代码但无法执行?

CFErrorRef error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
if (addressBook != nil) {
NSLog(@"Succesful.");
allContacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSLog(@"allContacts.count = %d",[allContacts count]);} allContact count is always zero

最佳答案

@property (nonatomic, assign) ABAddressBookRef addressBook;

//检查用户权限

 -(void)requestAddressBookAccess
{
ViewController * __weak weakSelf = self;

ABAddressBookRequestAccessWithCompletion(self.addressBook, ^(bool granted, CFErrorRef error)
{
if (granted)
{
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf accessGrantedForAddressBook];

});
}
else{
}
});
}

//获取所有联系方式

 -(void)accessGrantedForAddressBook{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(
kCFAllocatorDefault,
CFArrayGetCount(people),
people
);
NSMutableArray *allNames = (__bridge NSMutableArray*)peopleMutable;
}

关于ios - 如何从 AddressBook 中获取联系人并将其存储在 iOS 7 中的数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23128708/

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