Bor*_*ris 2 iphone objective-c abaddressbook
我有一个大问题......我打算编写一个处理用户地址簿及其地址的应用程序.一切都很好 - 除了我无法确定addesse的类型是"工作","家"还是"其他"的事实.
有人知道如何获得家庭,工作和其他标签吗?
提前致谢
鲍里斯
这是我目前正在使用的功能:
+ (void)testing {
//Get the addressbook
ABAddressBookRef _addressBookRef = ABAddressBookCreate ();
//Fetch all contacts
NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);
//Walk the contacts
for (id record in allPeople) {
//Get the contact´s id
NSInteger recordId = ABRecordGetRecordID((ABRecordRef)record);
//Get the contact´s name and company
NSString* recordName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record);
NSString* recordCompany = (NSString *)ABRecordCopyValue((ABRecordRef)record, kABPersonOrganizationProperty);
//Get the contact´s addresses
CFTypeRef adressesReference = ABRecordCopyValue((ABRecordRef)record, kABPersonAddressProperty);
NSArray *adressesArray = (NSArray *)ABMultiValueCopyArrayOfAllValues(adressesReference);
CFRelease(adressesReference);
NSLog(@"ID: %d", recordId);
NSLog(@"Name: %@", recordName);
NSLog(@"Firma: %@", recordCompany);
for (NSString *adress in adressesArray) {
NSLog(@"Adresse: %@", adress);
}
[adressesArray release];
}
CFRelease(_addressBookRef);
[allPeople release];
NSLog(@"\n");
}
Run Code Online (Sandbox Code Playgroud)
这是日志输出:
ID:1名称:第一个用户Firma :( null)Adresse:{City = Reutlingen; 国家=德国; CountryCode = de; 街="一些街道"; ZIP = 23456; }
Adresse:{City = Reutlingen; 国家=德国; CountryCode = de; 州= BW; 街="街道2号"; ZIP = 98765; }
ID:2姓名:第二次接触Firma:Firma Adresse:{Country ="United States"; CountryCode = us; 街=测试; }
sha*_*oga 10
以下是如何获取地址簿值的方法:
ABMultiValueRef addresses = ABRecordCopyValue(ref, kABPersonAddressProperty);
for (CFIndex j = 0; j<ABMultiValueGetCount(addresses);j++){
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addresses, j);
CFStringRef typeTmp = ABMultiValueCopyLabelAtIndex(addreses, j);
CFStringRef labeltype = ABAddressBookCopyLocalizedLabel(typeTmp);
NSString *street = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStreetKey) copy];
NSString *city = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCityKey) copy];
NSString *state = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressStateKey) copy];
NSString *zip = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressZIPKey) copy];
NSString *country = [(NSString *)CFDictionaryGetValue(dict, kABPersonAddressCountryKey) copy];
[street release];
[city release];
[state release];
[zip release];
[country release];
CFRelease(dict);
CFRelease(type);
CFRelease(typeTmp);
}
CFRelease(addresses);
Run Code Online (Sandbox Code Playgroud)
标签类型是您正在寻找的.
祝你好运
归档时间: |
|
查看次数: |
4255 次 |
最近记录: |