地址簿电话号码(+45)前缀导致崩溃! [英] Address book Phone number (+45) prefix causing crash!

查看:290
本文介绍了地址簿电话号码(+45)前缀导致崩溃!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从iPhone地址簿中获取电话号码。

I am having trouble getting phone numbers from the iPhone Addressbook.

当号码不包含+45等国家/地区代码前缀时,没有问题,但如果它会,我的应用程序崩溃...

There is no problem when the number do not contain a country code prefix like +45, but if it does, my app crashes...

这是一个已知的问题吗?我尚未找到任何相关内容...

Is this a known issue? I haven't been able to find anything about it...

感谢

编辑:

我得到这样的phonenumber:

I get phonenumber like this:

    -(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;
        }


推荐答案

书对象,一旦它被检索,你如何处理它来获取从它的数字。我使用下面显示的代码做同样的你提到,并准确提取数字。

How are you retrieving your Address book object, and once it is retrieved how do you process it to fetch the number from it.I am using the below shown code to do the same what you have mentioned and it fetches the numbers accurately.

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;
    }
}

确定它会帮助你。

干杯

这篇关于地址簿电话号码(+45)前缀导致崩溃!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆