gpt4 book ai didi

iphone - 从通讯录中获取号码

转载 作者:行者123 更新时间:2023-12-03 20:26:02 27 4
gpt4 key购买 nike

我想从电话簿中获取选择用户的号码。目前我只能得到他的名字。

- (IBAction) showPhoneBook: (id)sender {
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}

- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker {
[self dismissModalViewControllerAnimated:YES];
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {

// Select phone number
NSString* name = (NSString *)ABRecordCopyValue(person,
kABPersonFirstNameProperty);

self.number.text = name;

[name release];
[self dismissModalViewControllerAnimated:YES];
return NO;
}

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier{
return NO;
}

如何获取号码而不是名字?

致以诚挚的问候。

最佳答案

要从记录中获取电话号码,您可以执行以下操作(在回调方法内):

ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSArray* phoneNumbers = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);
CFRelease(phoneNUmberProperty);

// Do whatever you want with the phone numbers
NSLog(@"Phone numbers = %@", phoneNumbers);
[phoneNumbers release];

更新

ABMultiValueRef phones =(NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString* mobile=@"";
NSString* mobileLabel;
for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
{
[mobile release] ;
mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
}

关于iphone - 从通讯录中获取号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5879397/

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