Sample code for writing/updating multi-valued properties to the address book?
09/09/03 18:27
I can't find examples of code showing how to manipulate these AB properties…
Here an very basic example how to set emails and addresses:(field_XXX are the variables that should contain your data)
ABPerson *newRecord = [[ABPerson alloc] init] ;
ABMutableMultiValue *aMultiValue = [[[ABMutableMultiValue alloc] init] autorelease];
[aMultiValue addValue:field_WorkEMail withLabel:kABEmailWorkLabel];
[aMultiValue addValue:field_HomeEMail withLabel:kABEmailHomeLabel];
[newRecord setValue:aMultiValue forProperty:kABEmailProperty];
aMultiValue = [[[ABMutableMultiValue alloc] init] autorelease];
NSMutableDictionary *aDict = [NSMutableDictionary dictionaryWithCapacity:6];
[aDict setObject:field_WorkStreet forKey:kABAddressStreetKey];
[aDict setObject:field_WorkZIP forKey:kABAddressZIPKey];
[aDict setObject:field_WorkCity forKey:kABAddressCityKey];
[aDict setObject:field_WorkState forKey:kABAddressStateKey];
[aDict setObject:field_WorkCountryCode forKey:kABAddressCountryCodeKey];
[aDict setObject:field_WorkCountry forKey:kABAddressCountryKey];
[aMultiValue addValue:aDict withLabel:kABAddressWorkLabel];
aDict = [[NSMutableDictionary dictionaryWithCapacity:6] autorelease];
[aDict setObject:field_HomeStreet forKey:kABAddressStreetKey];
[aDict setObject:field_HomeZIP forKey:kABAddressZIPKey];
[aDict setObject:field_HomeCity forKey:kABAddressCityKey];
[aDict setObject:field_HomeState forKey:kABAddressStateKey];
[aDict setObject:field_HomeCountryCode forKey:kABAddressCountryCodeKey];
[aDict setObject:field_HomeCountry forKey:kABAddressCountryKey];
[aMultiValue addValue:aDict withLabel:kABAddressHomeLabel];
[newRecord setValue:aMultiValue forProperty:kABAddressProperty];
etc.
ABPerson *newRecord = [[ABPerson alloc] init] ;
ABMutableMultiValue *aMultiValue = [[[ABMutableMultiValue alloc] init] autorelease];
[aMultiValue addValue:field_WorkEMail withLabel:kABEmailWorkLabel];
[aMultiValue addValue:field_HomeEMail withLabel:kABEmailHomeLabel];
[newRecord setValue:aMultiValue forProperty:kABEmailProperty];
aMultiValue = [[[ABMutableMultiValue alloc] init] autorelease];
NSMutableDictionary *aDict = [NSMutableDictionary dictionaryWithCapacity:6];
[aDict setObject:field_WorkStreet forKey:kABAddressStreetKey];
[aDict setObject:field_WorkZIP forKey:kABAddressZIPKey];
[aDict setObject:field_WorkCity forKey:kABAddressCityKey];
[aDict setObject:field_WorkState forKey:kABAddressStateKey];
[aDict setObject:field_WorkCountryCode forKey:kABAddressCountryCodeKey];
[aDict setObject:field_WorkCountry forKey:kABAddressCountryKey];
[aMultiValue addValue:aDict withLabel:kABAddressWorkLabel];
aDict = [[NSMutableDictionary dictionaryWithCapacity:6] autorelease];
[aDict setObject:field_HomeStreet forKey:kABAddressStreetKey];
[aDict setObject:field_HomeZIP forKey:kABAddressZIPKey];
[aDict setObject:field_HomeCity forKey:kABAddressCityKey];
[aDict setObject:field_HomeState forKey:kABAddressStateKey];
[aDict setObject:field_HomeCountryCode forKey:kABAddressCountryCodeKey];
[aDict setObject:field_HomeCountry forKey:kABAddressCountryKey];
[aMultiValue addValue:aDict withLabel:kABAddressHomeLabel];
[newRecord setValue:aMultiValue forProperty:kABAddressProperty];
etc.