本文介绍了如何在iPhone的通讯录中编辑联系人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的应用程序.我从通讯录添加联系人,请参见下面的代码,但是如何编辑我不知道的通讯录添加联系人.

I create one new application.i add the contact from address book see the code below but how to edit this add contact from address book i don't know .

谁能知道,然后给出示例代码或想法.

can any one have know then give the sample code or idea.

预先感谢您为我提供宝贵的时间.

thanx in advance give your valuable time for me.

//code for add contact in contact list 

ABRecordRef aRecord = ABPersonCreate(); 
CFErrorRef  anError = NULL; 
ABRecordSetValue(aRecord, kABPersonFirstNameProperty, 
                 txtfirstname.text, &anError); 
ABRecordSetValue(aRecord, kABPersonLastNameProperty, 
                 txtlastName.text, &anError); 
ABRecordSetValue(aRecord, kABPersonBirthdayProperty, 
                 [datepick date], &anError); 
ABRecordSetValue(aRecord, kABPersonPhoneProperty, 
                 txtMobileNo, &anError); 
ABRecordSetValue(aRecord, kABPersonEmailProperty, 
                 txtEmailID, &anError); 
if (anError != NULL) 
{ 
    NSLog(@"error while creating..");
} 
CFStringRef firstName, lastName,birthDay; 
firstName = ABRecordCopyValue(aRecord, kABPersonFirstNameProperty); 
lastName  = ABRecordCopyValue(aRecord, kABPersonLastNameProperty); 
birthDay  = ABRecordCopyValue(aRecord, kABPersonBirthdayProperty); 

ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(email, txtEmailID.text, CFSTR("email"), NULL);
ABRecordSetValue(aRecord, kABPersonEmailProperty, email, &anError);
CFRelease(email);

ABMutableMultiValueRef multiPhone =  ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone,txtMobileNo.text, kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(aRecord, kABPersonPhoneProperty, multiPhone,nil);
CFRelease(multiPhone);

UIImage *personImage;   
personImage = tempimage;
NSData *dataRef = UIImagePNGRepresentation(personImage); 
CFDataRef dr = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
CFErrorRef error = NULL; 

ABPersonSetImageData(aRecord, dr, &error);  


ABAddressBookRef addressBook; 
addressBook = ABAddressBookCreate(); 

BOOL isAdded = ABAddressBookAddRecord (addressBook,aRecord,&error);

if(isAdded)
{
    NSLog(@"added..");
}
if (error != NULL) {
    NSLog(@"ABAddressBookAddRecord %@", error);
} 
error = NULL;

BOOL isSaved = ABAddressBookSave (addressBook,&error);

if(isSaved)
{
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Contact Save"
                                                        message:nil delegate:self 
                                              cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
    NSLog(@"saved..");
}

if (error != NULL) 
{
    NSLog(@"ABAddressBookSave %@", error);
} 

CFRelease(aRecord); 
CFRelease(firstName); 
CFRelease(lastName);
    CFRelease(birthDay); 
CFRelease(addressBook);

推荐答案

Apple的示例项目QuickContacts涵盖了以下内容: http://developer.apple.com/library/ios/#samplecode/QuickContacts/Introduction/Intro.html .

Apple's sample project QuickContacts covers this: http://developer.apple.com/library/ios/#samplecode/QuickContacts/Introduction/Intro.html.

我希望它对您有帮助.

这篇关于如何在iPhone的通讯录中编辑联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 19:53