2

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?

4

1 回答 1

0

研究使用 libsqlite3.dylib 并创建一个 sql 数据库,该数据库将访问为所有属性生成的平面文件。

带有 sqlite3 库的示例 iOS 项目在这里:

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

& 在这里使用 ABAddressbook 为联系人的多值属性执行此操作的详细信息:

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

于 2014-06-03T13:10:52.350 回答