/ Published in: Objective C
                    
                                        
Add the following framework "AddressBook.framework" to your project
Make sure to import these header files.
#import "AddressBook/ABAddressBook.h"
#import "AddressBook/ABPerson.h"
#import "AddressBook/ABMultiValue.h"
                Make sure to import these header files.
#import "AddressBook/ABAddressBook.h"
#import "AddressBook/ABPerson.h"
#import "AddressBook/ABMultiValue.h"
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
//This code is working properly in my project. Hope it helps you too.
#pragma mark -
#pragma mark addToAddressBook
- (IBAction)addToAddressBook
{
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();
CFErrorRef error = NULL;
ABRecordSetValue(person, kABPersonOrganizationProperty, venue.name, &error);
// a single url as the home page
ABMutableMultiValueRef urlMultiValue =
ABMultiValueCreateMutable(kABStringPropertyType);
ABMultiValueAddValueAndLabel(urlMultiValue, @"http://www.clubplanet.com",
kABPersonHomePageLabel, NULL);
ABRecordSetValue(person, kABPersonURLProperty, urlMultiValue, &error);
CFRelease(urlMultiValue);
if (venue.phone) {
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, venue.phone, kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, multiPhone, &error);
CFRelease(multiPhone);
}
ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
//Create a Disctionary Array to hold the address
if (venue.address) [addressDictionary setObject:venue.address forKey:(NSString *)kABPersonAddressStreetKey];
if (venue.city) [addressDictionary setObject:venue.city forKey:(NSString *)kABPersonAddressCityKey];
if (venue.state) [addressDictionary setObject:venue.state forKey:(NSString *)kABPersonAddressStateKey];
ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, multiAddress,&error);
CFRelease(multiAddress);
ABAddressBookAddRecord(addressBook, person, &error);
ABAddressBookSave(addressBook, &error);
if (error != NULL)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Could not create unknown user"
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
[alert release];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add To Contacts"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
CFRelease(person);
}
URL: http://www.espinallab.com
Comments
 Subscribe to comments
                    Subscribe to comments
                
                