Re: Archiving ABPerson
Re: Archiving ABPerson
- Subject: Re: Archiving ABPerson
- From: "Dr. H. Nikolaus Schaller" <email@hidden>
- Date: Sat, 8 May 2004 12:27:18 +0200
I just rean into the same issue.
To me it appears that it is not a bug in addRecord: but in
initWithVCardRepresentation: as the message appears just when this
method is called.
A workaround is:
@implementation ABPerson (archiving)
- (void) encodeWithCoder:(NSCoder *) coder;
{
[coder encodeDataObject:[self vCardRepresentation]];
}
- (id) initWithCoder:(NSCoder *)decoder;
{
self=[self init]; // this call assigns a uniqueId
self=[self initWithVCardRepresentation:[decoder decodeDataObject]];
return self;
}
@end
Ths unfortunate thing about this workaround is that it might fail when
Apple repairs the bug in initWithVCardRepresentation:
Nikolaus
Am 08.05.2004 um 05:34 schrieb Vince DeMarco:
On May 7, 2004, at 5:40 PM, Scott Ahten wrote:
I've received several useful hints for concatenating aloc and init
messages into a single line. Very helpful.
However, I've run into an interesting problem when attempting to
insert a ABPerson back into the address book DB after it has been
reconstructed from vCard data. When i call addRecord: I receive
several of the following error messages, then the application
crashes.
2004-05-07 18:34:48.875 Picture Sharing Browser[4490] *** Assertion
failure in -[ABAddressBook recordClassFromUniqueId:],
Framework/AddressBook/ABAddressBook.m:1295
When I look at the description of a person recreated from vCard data,
the person object seems to be missing the entry
'UID = "EB19929A-4B72-11D7-AC10-000A957713B6:ABPerson";'
At the end of the description. In addition, it contains
'ABPersonFlags = 0' which, in the original, is present as
'ABPersonFlags = 32'.
This behavior happens even if the NSData object is not transmitted
over a network connection.
In my test sample, techniques 01 and 02 work as expected. Techniques
03 and 04 cause the error messages to be generated, then the
application crashes.
Here is my test case...
- (void)readAllTheData:(NSNotification *)aNotification {
NSLog(@"Received Notification");
ABAddressBook * ab = [ABAddressBook sharedAddressBook];
/* 01. Create new person from scratch */
//ABPerson * newPerson =[[[ABPerson alloc] init] autorelease];
/* 02. Get my entry from the local address book */
//ABPerson * newPerson = [ab me];
/* 03. Convert vCard data transmitted over the network to a
ABPerson */
//ABPerson * newPerson =[[ABPerson alloc]
initWithVCardRepresentation:
// [[aNotification userInfo]
objectForKey:NSFileHandleNotificationDataItem]];
/* 04. Get my entry from the local address book,
export it as NSData vCard and rebuild as ABPerson */
ABPerson * me = [ab me];
NSData * vCardData = [me vCardRepresentation];
ABPerson * newPerson =[[ABPerson alloc]
initWithVCardRepresentation: vCardData];
/* This works as expected, even when creating from vCard data*/
NSLog([newPerson description]);
[newPerson setValue:@"John"
forProperty:kABFirstNameProperty];
[newPerson setValue:@"Doe"
forProperty:kABLastNameProperty];
/* commenting out theses lines prevents the error message and
crash */
[ab addRecord:newPerson];
[ab save];
}
Any Ideas as to what I'm doing wrong? My guess is that I'm missing a
important memory management issue.
You aren't missing anything its a bug in Address Book. I'll forward
this off to the people who work on it to get you a workaround.
Thanks,
- Scott
On May 7, 2004, at 3:15 PM, Scott Ahten wrote:
Vince [and Aaron],
I had tried that earlier, but had problems converting the data back
into a ABPerson.
Being new to Objective-C, I failed to realize
- (id)initWithVCardRepresentation:(NSData *)vCardData;
was a instance message, not at class message. It's working fine now.
I guess this means I need to release my ABPerson instance, since I
allocated it instead of the ABPerson class.
ABPerson * person = [ABPerson alloc];
[person initWithVCardRepresentation:cardData];
Thanks,
- Scott
On May 7, 2004, at 1:51 PM, Vince DeMarco wrote:
On May 7, 2004, at 10:21 AM, Scott Ahten wrote:
Hello everyone,
I'm trying to create a keyed archive that contains a NSArray of
ABPersons. I am archiving the array so it can transmitted across a
network to multiple users. At the moment, I'm just trying to
archive an ABPerson. My test code looks something like this...
ABAddressBook * ab = [ABAddressBook sharedAddressBook];
ABPerson * person = [ab me];
NSMutableData *representationToSend;
NSKeyedArchiver *archiver;
representationToSend = [NSMutableData data];
archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutableData:representationToSend];
[archiver encodeObject:person forKey:@"abPerson"];
[archiver finishEncoding];
[archiver release];
This code returns the following error...
2004-05-07 12:43:02.037 Picture Sharing[3501] *** -[ABPerson
encodeWithCoder:]: selector not recognized
2004-05-07 12:43:02.037 Picture Sharing[3501] Exception raised
during posting of notification. Ignored. exception: ***
-[ABPerson encodeWithCoder:]: selector not recognized
Checking the headers, I found that ABPerson does not implement the
NSCoding interface. I assume lack of archive support is
intentional due to issues with it's implementation. Since I do not
have the source for ABPerson class, is it possible to extend or
modify it to support Archiving?
Any examples or resources would be greatly appreciated.
If you really want to do this then create a vcard and save that off
to the disk instead of doing this. ABRecords do not support
Archiving.
use these methods on ABPerson instead
- (id)initWithVCardRepresentation:(NSData *)vCardData;
// Create a person from a vCard
- (NSData *)vCardRepresentation;
// Returns nil if vCardData is nil or not a valid vCard
Then instead of sending the archive just send the NSData of the
vcard around.
vince
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
- - - - -
:: email@hidden
:: http://www.pixelfreak.net
- - - - -
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
- - - - -
:: email@hidden
:: http://www.pixelfreak.net
- - - - -
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
+------------------+
! email@hidden !
! make !
! software !
+------------------+
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.