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

发布于 2024-10-12 12:33:02 字数 1515 浏览 6 评论 0原文

我无法从 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;
        }

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

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...

Thanks

EDIT:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悸初 2024-10-19 12:33:02

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

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

我确信它会对你有所帮助。

干杯

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

Im sure it will help you.

Cheers

ι不睡觉的鱼゛ 2024-10-19 12:33:02

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

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

This solved my problem. Hope someone finds it helpful.

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文