Trying to allow user to save contact details from my app to their address book/contacts.
under IBAction:
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();
CFErrorRef anError = NULL;
ABRecordSetValue(person,kABPersonFirstNameProperty,@"Name goes here",&anError);
ABRecordSetValue(person, kABPersonOrganizationProperty, @"Company name here", &anError);
ABRecordSetValue(person, kABPersonJobTitleProperty, @"Job Title Here", &anError);
ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
[addressDictionary setObject:@"Chicago" forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary setObject:@"IL" forKey:(NSString *)kABPersonAddressStateKey];
[addressDictionary setObject:@"60654" forKey:(NSString *)kABPersonAddressZIPKey];
ABMultiValueAddValueAndLabel(multiAddress, @"Adress", (CFStringRef)@"Address", NULL);
ABRecordSetValue(person, kABPersonAddressProperty, multiAddress,&anError);
CFRelease(multiAddress);
ABMutableMultiValueRef websiteMultiValue = ABMultiValueCreateMutable(kABPersonURLProperty);
ABMultiValueAddValueAndLabel(websiteMultiValue, @"www.7app.co.uk", (CFStringRef)@"Website", NULL);
ABRecordSetValue(person, kABPersonURLProperty, websiteMultiValue, &anError);
ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABPersonEmailProperty);
ABMultiValueAddValueAndLabel(emailMultiValue, @"something@hotmail.com", (CFStringRef)@"Email", NULL);
ABRecordSetValue(person, kABPersonEmailProperty, emailMultiValue, &anError);
ABAddressBookAddRecord(addressBook, person, &anError);
}
Ive imported
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI>.h
Im getting no response at all when I press the button. Nothing at all happens. Just to mention this is my first attempt at using the address book framework if theres a glaring error.
I also wanted to save a contact pic with the following
NSData *dataRef = UIImagePNGRepresentation(my image here);
ABPersonSetImageData(person, (__bridge_retained CFDataRef)dataRef, nil);
However I get an exception thrown, ive decared an image in the ususal manner, not sure if that is appropriate for this method? Error msg im getting:
2012-07-17 19:01:50.132 543[966:707] -[UIImageView CGImage]: unrecognized selector sent to instance 0x15b9b0
2012-07-17 19:01:50.133 543[966:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView CGImage]: unrecognized selector sent to instance 0x15b9b0'
Normally when an exception is thrown its because of connection problem, I have double checked and the UI image has no duplicate connections etc.
Any advice as always appreciated