gpt4 book ai didi

iphone - 地址簿导致崩溃的电话号码(+45)前缀!

转载 作者:行者123 更新时间:2023-12-03 17:43:14 25 4
gpt4 key购买 nike

我在从iPhone地址簿中获取电话号码时遇到麻烦。

当该数字不包含国家代码前缀(如+45)时没有问题,但是如果确实如此,我的应用程序将崩溃...

这是一个已知的问题?我还没找到任何关于它的东西...

谢谢

编辑:

我得到这样的电话号码:

    -(void)getContact 
{

ABPeoplePickerNavigationController *pp = [[ABPeoplePickerNavigationController alloc] init];
pp.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
pp.peoplePickerDelegate = self;
[self presentModalViewController:pp animated:YES];
[pp release];


}

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
// assigning control back to the main controller
[self dismissModalViewControllerAnimated:YES];
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
return YES;
}

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

ABMultiValueRef phoneProperty = ABRecordCopyValue(person,property);
saveString = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,identifier);
saveString = [saveString stringByReplacingOccurrencesOfString:@" " withString:@""];
nummerTextField.text = saveString;
}

最佳答案

您如何检索通讯簿对象,一旦检索到该对象,您将如何处理该对象以从中获取编号。我正在使用下面显示的代码执行与您提到的相同的操作,它可以准确地获取编号。

ABRecordRef person = ABAddressBookGetPersonWithRecordID(appDelegate.addressBook, contactId);

ABMultiValueRef multiValue = ABRecordCopyValue(person, kABPersonPhoneProperty);

NSArray *allNumbers = (NSArray *)ABMultiValueCopyArrayOfAllValues(multiValue);
NSMutableDictionary *filteredNumbers = [NSMutableDictionary new];

if([allNumbers count] > 0) {
for(int contactIndex = 0; contactIndex < [allNumbers count]; contactIndex++) {
NSString *contactValue = (NSString *)ABMultiValueCopyLabelAtIndex(multiValue, contactIndex);
if(!([contactValue isEqualToString:@"_$!<WorkFAX>!$_"] || [contactValue isEqualToString:@"_$!<HomeFAX>!$_"] || [contactValue isEqualToString:@"_$!<Pager>!$_"])) {

if([[contactValue substringWithRange:contactLabelCharacterCustom] isEqualToString:@"_$"])
typeOfContact = [contactValue substringWithRange:contactLabelCharacter];
else
typeOfContact = [contactValue substringWithRange:(NSRange){0,1}];
NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, contactIndex);
[filteredNumbers setValue:typeOfContact forKey:value];
[value release];
value = nil;
}
[contactValue release];
contactValue = nil;
}
}

我确定它将为您提供帮助。

干杯

关于iphone - 地址簿导致崩溃的电话号码(+45)前缀!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4712071/

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