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

时间:2011-01-17 10:22:47

标签: 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;
        }

2 个答案:

答案 0 :(得分:0)

如何检索地址簿对象,一旦检索到它,如何处理它以从中获取数字。我使用下面显示的代码执行与您提到的相同的操作并准确提取数字

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

我相信它会对你有帮助。

干杯

答案 1 :(得分:0)

这解决了我的问题。希望有人觉得它有用。

ABMultiValueRef multiValue = ABRecordCopyValue(person, property);

        NSString *number = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, ABMultiValueGetIndexForIdentifier(multiValue, identifier));

// Error was here: NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, contactIndex);

        //Copy the number etc before cleaning everything up

        saveString = number;
        saveString = [saveString stringByReplacingOccurrencesOfString:@" " withString:@""];
        nummerTextField.text = saveString;

        [number release];
        CFRelease(multiValue);