作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个新的应用程序。我从地址簿中添加联系人,请参阅下面的代码,但我不知道如何编辑此从地址簿添加联系人。
任何人都可以知道然后给出示例代码或想法吗?
提前感谢您为我腾出宝贵的时间。
//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 .
希望对你有帮助。
关于iphone - 如何在 iPhone 中编辑地址簿中的联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10316825/
我是一名优秀的程序员,十分优秀!