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

标签 iphone crash addressbook prefix

我在从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/

相关文章:

iphone - label.layer.borderColor = .... 不工作(Xcode 4.3.2)

apache-flex - 启用rtmfp时,FMS服务器每天都会死亡

ios - kABPerson 属性 |知道地址簿联系人是否也在使用 iPhone?

ios - ABPersonRemoveImageData 在本地工作但不更新 iCloud

c# - 使用 C# 和 ASP.NET 从 Gmail/Hotmail/Yahoo 导入地址簿

ios - 保留 iOS 应用名称

iphone - App Store 提交错误 : A symbolic link resolves to a location outside of the binary

iphone - 如何限制 UILabel 文本长度 - IOS

debugging - 崩溃后查看内核日志

android - Tux Rider 编译但在启动时崩溃