tags:

views:

146

answers:

3

Using the standard add record code I am getting a very strange error when setting properties other than FirstName and Organization (the first 2 lines work):

ABRecordSetValue(person, kABPersonFirstNameProperty, location.title , nil);
ABRecordSetValue(person, kABPersonOrganizationProperty, location.title , nil);
ABRecordSetValue(person, kABPersonPhoneProperty, [location telephone], nil);
ABRecordSetValue(person, kABPersonAddressStreetKey, [location addressLine1], nil);
ABRecordSetValue(person, kABPersonAddressCityKey, [location addressTownCity], nil);
ABRecordSetValue(person, kABPersonAddressZIPKey, [location addressPostcode], nil);
ABRecordSetValue(person, kABPersonAddressStateKey, [location addressCounty], nil);

FYI it isnt the difference between location.title and [location addressLine1] as I have tried setting kABPersonAddressStreetKey to location.title with the same problem

Even with this code I get a EXC_BAD_ACCESS

ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();
ABRecordSetValue(person, kABPersonFirstNameProperty, location.title , nil);
ABRecordSetValue(person, kABPersonPhoneProperty, @"0208 1567890", nil);
ABAddressBookAddRecord(addressBook, person, nil);
ABAddressBookSave(addressBook, nil

Cause of the telephone line, I must be doing something stupid surely!?!?!?

A: 

Have you tried to debug to that specific line of code using the debugger to print out the value of location variable?

Or at least, log that variable's value to NSLog().

Edited:

In this case, I guess location variable do not respond to the selector methods.

Try to "Step Into" the line 3 to see what happens?

sfa
The values are just NSStrings and populated, I use them elsewhere throughout the application
tigermain
I edited the answer!
sfa
+1  A: 

Check the hints that are given in Finding EXC_BAD_ACCESS bugs in a Cocoa project.

Also useful in this case is the NSZombieEnabled feature as explained in Debugging Applications

St3fan
I have NSZombieEnabled set but it isnt giving me any more information in this case
tigermain
A: 

Ah it seems it is cause the telephone and address fields are multi value, I hadnt realised this

More details can be found

http://www.modelmetrics.com/tomgersic/iphone-programming-adding-a-contact-to-the-iphone-address-book/

tigermain