views:

14

answers:

1

I have an app that uses the user's Address Book for contacts. I also have other information I wish to store on a per-user basis (per Address Book entry basis). I allow the user to import a single user, an Address Book group, or all of their contacts. Because I wish to continue to allow outside applications to change the users Address Book, I do not import all the information. Instead I have chosen to alter the Address Book entry for each imported user, adding a kABPersonInstantMessageProperty key. I want populate to this key with [email protected] as the username. I figured this will immediately be seen by the end user as both a: unobtrusive, and b: a link to my app's info (hooking the outside contact info with the internal info my app adds and keeps). The only problem? I have NO idea how to add an entry to the kABPersonInstantMessageProperty key. I have figured out how to add multi-value entries such as "Home Address" but when searching stack overflow, I come up with 4 (ONLY FOUR!) entries on questions regarding this key (kABPersonInstantMessageProperty).

A portion of my code for adding "Home Address" to a person's Address Book entry is below and I admit that I have no idea how to change this over to kABPersonInstantMessageProperty.

 ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);  
 NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];

 NSMutableString *street = [NSMutableString stringWithFormat:@"%i",i];
 [street appendString:@" Main Street"];

 [addressDict setObject:[NSString stringWithString:street] forKey:(NSString *)kABPersonAddressStreetKey];       
 [addressDict setObject:@"San Jose" forKey:(NSString *)kABPersonAddressCityKey]; 
 [addressDict setObject:@"CA" forKey:(NSString *)kABPersonAddressStateKey]; 

 NSMutableString *zip = [NSMutableString stringWithString:@"95"];
 [zip appendString:[NSString stringWithFormat:@"%00i",i]];

 [addressDict setObject:zip forKey:(NSString *)kABPersonAddressZIPKey];      
 ABMultiValueAddValueAndLabel(address, addressDict, kABHomeLabel, NULL);
 ABRecordSetValue(record, kABPersonAddressProperty, address, NULL); 

 // add the record
 ABAddressBookAddRecord(addressBook, record, NULL);

Can someone help? I would appreciate it.

A: 

GOT IT!

This is so simple! Thanks to link text who had the same issue with lack of Google-able answers on this one. Thanks, Casey!

Whereas record is the ABPerson record and all the ABCreate stuff has already been done and i is the sequential record locator integer...

        ABMutableMultiValueRef im = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
        NSMutableDictionary *imDict = [[NSMutableDictionary alloc] init];
        [imDict setObject:@"MyAppName"  forKey:(NSString*)kABPersonInstantMessageServiceKey];

        NSMutableString *iMID = [NSMutableString stringWithFormat:@"%i",i];
        [iMID appendString:@"RL@MyAppDomain"];

        [imDict setObject:iMID forKey:(NSString*)kABPersonInstantMessageUsernameKey];
        ABMultiValueAddValueAndLabel(im, imDict, kABHomeLabel, NULL);
        [imDict release];
        ABRecordSetValue(record, kABPersonInstantMessageProperty, im, NULL);
Jann