gpt4 book ai didi

ios - 我怎样才能得到联系ID

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:17:20 27 4
gpt4 key购买 nike

我在从地址簿中获取联系人 ID 时遇到问题。

我的 .m 文件:

-(IBAction)test:(id)sender
{
ABPeoplePickerNavigationController* picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController:picker animated:YES completion:nil];
}

-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
[peoplePicker dismissViewControllerAnimated:YES completion:nil];
ABRecordID recordID = ABRecordGetRecordID(person);
label.text = [NSString stringWithFormat:@"%d", recordID];

}

-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[peoplePicker dismissViewControllerAnimated:YES completion:nil];
}

我将 AddressBook 和 AddressBookUI 导入到 .h 文件中。一切正常,但我得到了错误的 ID。每次我只得到 ID -1,这代表错误。

希望你能帮助我。

非常感谢,基督徒

最佳答案

在 iOS 8 中,当仅显示联系人选择器时,它不再自动请求地址簿权限。 (这个想法是,选择器本身并没有真正让应用程序访问您的联系人,因此不需要任何许可。当应用程序没有真正获取联系人详细信息时,它提供低摩擦 UI。)

但是,在您的情况下,您实际上是在尝试以编程方式检索有关联系人的信息。为此,您确实需要许可。因此,在显示选择器之前,您可能需要请求访问地址簿的权限:

ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus();
if ((status == kABAuthorizationStatusDenied || status == kABAuthorizationStatusRestricted)) {
NSLog(@"User previously denied permission; show error message that they must go to settings and give this app permission");
return;
} else if (status == kABAuthorizationStatusNotDetermined) {
CFErrorRef error;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
if (!addressBook) {
NSLog(@"unable to open address book: %@", CFBridgingRelease(error));
return;
}

ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted) {
NSLog(@"OK");
} else {
NSLog(@"Not ok");
}

CFRelease(addressBook);
});
}

关于ios - 我怎样才能得到联系ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28750625/

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