如何从 iPhone 通讯录中检索手机号码。

发布于 2024-09-15 09:43:46 字数 533 浏览 5 评论 0原文

我使用以下代码在我的应用程序中设置检索电话号码。

CFStringRef addressBookMobile;
ABRecordRef person;
NSString *mobile;

person = CFArrayGetValueAtIndex(people, i);
addressBookMobile = ABRecordCopyValue(person, kABPersonPhoneProperty);
mobile = [NSString stringWithFormat:@"%@", addressBookMobile];

联系人的标签是“移动”。但是,当我使用 NSLog(@"%@", mobile); 时。它显示 。我的代码有什么问题吗?

我应该使用 const CFStringRef kABPersonPhoneMobileLabel 以及如何使用?如果我将其替换为上面的代码,则会出现错误。谁能帮助我吗?谢谢。

I use the following code to set the retrieve the phone number in my app.

CFStringRef addressBookMobile;
ABRecordRef person;
NSString *mobile;

person = CFArrayGetValueAtIndex(people, i);
addressBookMobile = ABRecordCopyValue(person, kABPersonPhoneProperty);
mobile = [NSString stringWithFormat:@"%@", addressBookMobile];

The tag of the contacts is 'mobile'. However, when I use the NSLog(@"%@", mobile); . It displays the <NSCFType: 0x802ffc0>. does any problem for my code?

Should I use the const CFStringRef kABPersonPhoneMobileLabel and how to use? As if I replace it as the above code, it has the error. Can anyone help me? Thank you.

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

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

发布评论

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

评论(4

平生欢 2024-09-22 09:43:46

检查 ABPerson 参考,您不需要使用 @"$!!$" 而是 kABPersonPhoneMobileLabel。例子是:

    ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString* mobile=@"";
    NSString* mobileLabel;
    for (int i=0; i < ABMultiValueGetCount(phones); i++) {
        //NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phones, i);
        //NSLog(@"%@", phone);
        mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
        if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
            NSLog(@"mobile:");
        } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel]) {
            NSLog(@"iphone:");
        } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhonePagerLabel]) {
            NSLog(@"pager:");
        }
        [mobile release];
        mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
        NSLog(@"%@", mobile);
    }

check the ABPerson Refrence and You need't use @"$!!$" but kABPersonPhoneMobileLabel. the example is:

    ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(person, kABPersonPhoneProperty);
    NSString* mobile=@"";
    NSString* mobileLabel;
    for (int i=0; i < ABMultiValueGetCount(phones); i++) {
        //NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phones, i);
        //NSLog(@"%@", phone);
        mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
        if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
            NSLog(@"mobile:");
        } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel]) {
            NSLog(@"iphone:");
        } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhonePagerLabel]) {
            NSLog(@"pager:");
        }
        [mobile release];
        mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
        NSLog(@"%@", mobile);
    }
日记撕了你也走了 2024-09-22 09:43:46

地址簿中人员的电话号码采用多值属性的形式。

在你的情况下,你应该有类似下面的东西(还没有尝试过,直接在此处输入,所以我不知道它是否可以编译和/或工作):

ABMultiValueRef phoneNumbers = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *mobileNumber;
NSString *mobileLabel;
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
    mobileLabel = (NSString *)ABMultiValueCopyLabelAtIndex(mobilePhones, i);
    if ([mobileLabel isEqualToString:@"mobile"]) {
        mobileNumber = (NSString*)ABMultiValueCopyValueAtIndex(mobilePhones,i);
        break;
    }
}

The phone numbers of a person in the Address Book are in the form of a multi-value property.

In your case, you should have something like the following (haven't tried it, typing directly here, so I don't know if it compiles and/or works):

ABMultiValueRef phoneNumbers = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString *mobileNumber;
NSString *mobileLabel;
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
    mobileLabel = (NSString *)ABMultiValueCopyLabelAtIndex(mobilePhones, i);
    if ([mobileLabel isEqualToString:@"mobile"]) {
        mobileNumber = (NSString*)ABMultiValueCopyValueAtIndex(mobilePhones,i);
        break;
    }
}
嘿哥们儿 2024-09-22 09:43:46
ABMultiValueRef phoneNumbers = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);
CRStringRef mobileNumber;
CRStringRef mobileLabel;
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
    mobileLabel = ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
    if ([mobileLabel isEqualToString:@"_$!<Mobile>!$_"]) {
        mobileNumber = ABMultiValueCopyValueAtIndex(phoneNumbers,i);
        break;
    }
}
ABMultiValueRef phoneNumbers = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);
CRStringRef mobileNumber;
CRStringRef mobileLabel;
for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
    mobileLabel = ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
    if ([mobileLabel isEqualToString:@"_$!<Mobile>!$_"]) {
        mobileNumber = ABMultiValueCopyValueAtIndex(phoneNumbers,i);
        break;
    }
}
孤檠 2024-09-22 09:43:46

这对于 ARC 64 位 iOS8 来说是可靠的:

- (NSArray *)phoneNumbersOfContactAsStrings:(ABRecordRef)contactRef {

NSMutableArray *mobilePhones = [NSMutableArray arrayWithCapacity:0];

ABMultiValueRef phones = ABRecordCopyValue(contactRef, kABPersonPhoneProperty);
NSArray *allPhoneNumbers = (NSArray *)CFBridgingRelease(ABMultiValueCopyArrayOfAllValues(phones));

for (NSUInteger i=0; i < [allPhoneNumbers count]; i++) {
    if ([(NSString *)CFBridgingRelease(ABMultiValueCopyLabelAtIndex(phones, (long)i)) isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
        [mobilePhones addObject:CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, (long)i))];
    }
    if ([(NSString *)CFBridgingRelease(ABMultiValueCopyLabelAtIndex(phones, (long)i)) isEqualToString:(NSString *)kABPersonPhoneIPhoneLabel]) {
        [mobilePhones addObject:CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, (long)i))];
    }
}

CFRelease(phones);
return mobilePhones;
}

This is solid for ARC 64bit iOS8:

- (NSArray *)phoneNumbersOfContactAsStrings:(ABRecordRef)contactRef {

NSMutableArray *mobilePhones = [NSMutableArray arrayWithCapacity:0];

ABMultiValueRef phones = ABRecordCopyValue(contactRef, kABPersonPhoneProperty);
NSArray *allPhoneNumbers = (NSArray *)CFBridgingRelease(ABMultiValueCopyArrayOfAllValues(phones));

for (NSUInteger i=0; i < [allPhoneNumbers count]; i++) {
    if ([(NSString *)CFBridgingRelease(ABMultiValueCopyLabelAtIndex(phones, (long)i)) isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
        [mobilePhones addObject:CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, (long)i))];
    }
    if ([(NSString *)CFBridgingRelease(ABMultiValueCopyLabelAtIndex(phones, (long)i)) isEqualToString:(NSString *)kABPersonPhoneIPhoneLabel]) {
        [mobilePhones addObject:CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, (long)i))];
    }
}

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