Created
April 29, 2011 16:46
-
-
Save petershine/948604 to your computer and use it in GitHub Desktop.
An implementation to return ABPersonRecord as commonly used id object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (id)personRecordUsingModelObj:(id)modelObj { | |
ABRecordRef aContact = ABPersonCreate(); | |
CFErrorRef anError = NULL; | |
NSString *name = [NSString stringWithFormat:@"%@", [modelObj name]]; | |
ABRecordSetValue(aContact, kABPersonOrganizationProperty, name, &anError); | |
ABMultiValueRef phone = ABMultiValueCreateMutable(kABMultiStringPropertyType); | |
ABMultiValueAddValueAndLabel(phone, [modelObj phone], kABPersonPhoneMainLabel, NULL); | |
ABRecordSetValue(aContact, kABPersonPhoneProperty, phone, &anError); | |
CFRelease(phone); | |
NSString *address = [NSString stringWithFormat:@"%@ %@", [modelObj addr1], [modelObj addr2]]; | |
NSMutableDictionary *dictionaryAddress = [[NSMutableDictionary alloc] initWithCapacity:0]; | |
[dictionaryAddress setObject:address forKey:(NSString *)kABPersonAddressStreetKey]; | |
[dictionaryAddress setObject:@"us" forKey:(NSString *)kABPersonAddressCountryCodeKey]; | |
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABDictionaryPropertyType); | |
ABMultiValueAddValueAndLabel(address, dictionaryAddress, kABPersonAddressStreetKey, NULL); | |
[dictionaryAddress release]; | |
ABRecordSetValue(aContact, kABPersonAddressProperty, address, &anError); | |
CFRelease(address); | |
if (anError) { | |
aContact = nil; | |
} | |
[(id)aContact autorelease]; | |
return (id)aContact; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment