Question

I want to store the Content of a ABRecordRef in my own Application independent of the entry in the AdressBook. After crossreading through stackoverflow and the apple developers site i found this to be the best way:

If got that right, one would need a NSCoding conform NSObject subclass with all values of ABRecordRef and at least the functions initWithABRecordRef and getABRecordRefFromPeopleData (assuming one names his class peopleData), where initWithABRecordRef would fill all values from an ABRecordRef (if not null) into an instance of the own class and getABRecordRefFromPeopleData returns an ABRecordRef opaque type with the Data stored in an instance of the own class.

My question to that:

I wonder if someone out there already did that, because I can imagine, other people came to the exact same problem before. If so, getting hands on that class would be aewsome, if not i am going to give it a try on my own and load the results up here if wanted. Maybe you even know a better way to do that?

If you did implement a solution, please share it. If you need the same, I'd appreciate working that out together.

Edit:

I now started working on the thing and (as i expected) i ran into some unclear problems. As it comes to kABStringPropertyType values my concept is pretty straight forward. Small example:

@implementation RealRecord
@synthesize firstName; //NSString

- (id)initWithRecordRef:(ABRecordRef)record{

    //Single valued entrys
    NSString *contactName = (NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
    firstName=contactName;
    [contactName release];
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder{
    //single value entrys
    self.firstName=             [aDecoder decodeObjectForKey:@"firstName"];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:firstName forKey:@"firstName"];
}

- (ABRecordRef)returnABRecordRefFromRealRecord{
    ABRecordRef returnRecord =ABPersonCreate();
    ABRecordSetValue(returnRecord, kABPersonFirstNameProperty, firstName, NULL);
    return returnRecord;
}

This works fine. Now im not so clear with how to do the same thing with the kABMultiStringPropertyType.I made me a NSMutableArray emailList and went on like this:

- (id)initWithRecordRef:(ABRecordRef)record{

    //Multi valued entrys
ABMutableMultiValueRef email=ABRecordCopyValue(record, kABPersonEmailProperty);
for (int i = 0; i < ABMultiValueGetCount(email); i++) {
    NSString *anEmail = [(NSString*)ABMultiValueCopyValueAtIndex(email, i) autorelease];
    [emailList addObject:anEmail];
}
return self;
}

Now im not shure, how to do the rest of the tasks on the multi values. Can i just encode and decode the NSMutableArray like i did with the Strings or do i have to set a key for all of the emails in emailList?

And how do i get the damn thing back into the returnRecord?

Was it helpful?

Solution

Look into using libsqlite3.dylib and creating a sql database that will access the flat files generated for all the properties.

Sample iOS project with sqlite3 library is here:

http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_7_Application

& Detail on doing so with ABAddressbook for contact's multi-value properties here:

http://linuxsleuthing.blogspot.com/2012/10/addressing-ios6-address-book-and-sqlite.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top