Que*_*ons 5 iphone objective-c contacts
我使用以下代码设置检索我的应用程序中的电话号码.
CFStringRef addressBookMobile;
ABRecordRef person;
NSString *mobile;
person = CFArrayGetValueAtIndex(people, i);
addressBookMobile = ABRecordCopyValue(person, kABPersonPhoneProperty);
mobile = [NSString stringWithFormat:@"%@", addressBookMobile];
Run Code Online (Sandbox Code Playgroud)
联系人的标签是"移动的".但是,当我使用的时候NSLog(@"%@", mobile);.它显示了<NSCFType: 0x802ffc0>.我的代码有什么问题吗?
我应该使用const CFStringRef kABPersonPhoneMobileLabel和如何使用?好像我将它替换为上面的代码,它有错误.谁能帮我?谢谢.
小智 16
检查ABPerson Refrence,你不需要使用@" $ !! $ "但是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);
}
Run Code Online (Sandbox Code Playgroud)
地址簿中某人的电话号码采用多值属性的形式.
在你的情况下,你应该有类似以下的东西(没有尝试过,直接在这里打字,所以我不知道它是否编译和/或工作):
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;
}
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7330 次 |
| 最近记录: |