1
나는 Obsolete ABAdressBook 코드를 Objective C의 현재 CNContact 프레임 워크로 대체하려고합니다. 홈 시티 부분을 제외하고 대부분을 정리할 수 있습니다. 초점을 맞추도록하겠습니다. 현재이 코드가 있습니다iOS +9의 연락처 프레임 워크에서 Home City를 얻는 방법은 무엇입니까?
-(NSArray *)getLandAddressesForContactIOS6:(ABRecordRef)recordRef {
ABMultiValueRef addresses = ABRecordCopyValue(recordRef, kABPersonAddressProperty);
NSMutableArray *formattedAddressesResponse = [NSMutableArray array];
for(CFIndex i = 0; i < ABMultiValueGetCount(addresses); i++) {
NSString *label = (__bridge NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(addresses, i));
NSDictionary *addressComponents = (__bridge NSDictionary*)ABMultiValueCopyValueAtIndex(addresses, i);
NSString *street = [addressComponents objectForKey:(NSString *)kABPersonAddressStreetKey];
NSString *city = [addressComponents objectForKey:(NSString *)kABPersonAddressCityKey];
NSString *formattedAddress = ABCreateStringWithAddressDictionary(addressComponents, YES);
NSMutableDictionary *currentAddressResponse = [NSMutableDictionary dictionaryWithObjectsAndKeys:
label, @"type",
label, @"label",
nil];
if (street != nil) {
[currentAddressResponse setObject:street forKey:@"street"];
}
if (city != nil) {
[currentAddressResponse setObject:city forKey:@"city"];
}
if (formattedAddress != nil) {
[currentAddressResponse setObject:formattedAddress forKey:@"formattedAddress"];
}
[formattedAddressesResponse addObject:currentAddressResponse];
}
return formattedAddressesResponse;
}
그 코드가 iOS 용되지 않습니다 9 + I 새로운 연락처 프레임 워크와 홈 도시를 얻을 가지고 가장 가까운 있도록이다 :
-(NSArray *)getLandAddressesForContactIOS10:(CNContact*)recordRef {
NSArray <CNLabeledValue<CNPostalAddress *> *> *addresses = recordRef.postalAddresses;
NSMutableArray *formattedAdressResponse = [NSMutableArray array];
for(CFIndex i = 0; i < addresses.count; i++) {
CNLabeledValue *addressi = [addresses objectAtIndex:i];
//NSString *city = addressi.??????; //Stuck here, don't know what else to do
어떻게 할 수 CNContact에서 도시 이름을 추출 하시겠습니까 ??