增加个人信息到通讯录
来源:互联网 发布:部门考核数据流程图 编辑:程序博客网 时间:2024/04/28 07:58
#pragma mark -
#pragma mark Add a person to Address Book
- (IBAction)addPersonButton:(id)sender {
UITableViewCell *cell=(UITableViewCell *)[sender superview];
ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;
// Username
UILabel *label = (UILabel *)[cell viewWithTag:11];
NSString *username = [[NSString alloc] initWithFormat:@"%@",label.text];
NSLog(@"%@",label.text);
ABRecordSetValue(aRecord, kABPersonFirstNameProperty, username, &anError);
[username release];
// Phone Number
label = (UILabel *)[cell viewWithTag:12];
NSLog(@"%@",label.text);
NSString *usercontact = [[NSString alloc] initWithFormat:@"%@",label.text];
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multi, (CFStringRef)usercontact, kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(aRecord, kABPersonPhoneProperty, multi, &anError);
CFRelease(multi);
[usercontact release];
// Company
label = (UILabel *)[cell viewWithTag:13];
NSLog(@"%@",label.text);
NSString *usercompany = [[NSString alloc] initWithFormat:@"%@",label.text];
ABRecordSetValue(aRecord, kABPersonDepartmentProperty, usercompany, &anError);
[usercompany release];
// image
UIImageView *imageView=(UIImageView*) [cell viewWithTag:10];
NSData *dataref = UIImagePNGRepresentation(imageView.image);
UIImage *defultImage =[UIImage imageNamed:@"pic_s_head.png"];
NSData *defultImageData = UIImagePNGRepresentation(defultImage);
if (dataref == nil) {
dataref = UIImageJPEGRepresentation(imageView.image, 1);
}
if (![dataref isEqualToData:defultImageData]) {
ABPersonSetImageData(aRecord, (CFDataRef) dataref , &anError);
}
if (anError != NULL)
NSLog(@"error while creating..");
ABAddressBookRef addressBook;
CFErrorRef error = NULL;
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) {
NSLog(@"saved..");
UIAlertView *alertOnChoose = [[UIAlertView alloc] initWithTitle:@"Phone added successfully to your addressbook" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertOnChoose show];
[alertOnChoose release];
}
if (error != NULL) {
NSLog(@"ABAddressBookSave %@", error);
UIAlertView *alertOnChoose = [[UIAlertView alloc] initWithTitle:@"Unable to save this time" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertOnChoose show];
[alertOnChoose release];
}
CFRelease(aRecord);
}
#pragma mark Add a person to Address Book
- (IBAction)addPersonButton:(id)sender {
UITableViewCell *cell=(UITableViewCell *)[sender superview];
ABRecordRef aRecord = ABPersonCreate();
CFErrorRef anError = NULL;
// Username
UILabel *label = (UILabel *)[cell viewWithTag:11];
NSString *username = [[NSString alloc] initWithFormat:@"%@",label.text];
NSLog(@"%@",label.text);
ABRecordSetValue(aRecord, kABPersonFirstNameProperty, username, &anError);
[username release];
// Phone Number
label = (UILabel *)[cell viewWithTag:12];
NSLog(@"%@",label.text);
NSString *usercontact = [[NSString alloc] initWithFormat:@"%@",label.text];
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multi, (CFStringRef)usercontact, kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(aRecord, kABPersonPhoneProperty, multi, &anError);
CFRelease(multi);
[usercontact release];
// Company
label = (UILabel *)[cell viewWithTag:13];
NSLog(@"%@",label.text);
NSString *usercompany = [[NSString alloc] initWithFormat:@"%@",label.text];
ABRecordSetValue(aRecord, kABPersonDepartmentProperty, usercompany, &anError);
[usercompany release];
// image
UIImageView *imageView=(UIImageView*) [cell viewWithTag:10];
NSData *dataref = UIImagePNGRepresentation(imageView.image);
UIImage *defultImage =[UIImage imageNamed:@"pic_s_head.png"];
NSData *defultImageData = UIImagePNGRepresentation(defultImage);
if (dataref == nil) {
dataref = UIImageJPEGRepresentation(imageView.image, 1);
}
if (![dataref isEqualToData:defultImageData]) {
ABPersonSetImageData(aRecord, (CFDataRef) dataref , &anError);
}
if (anError != NULL)
NSLog(@"error while creating..");
ABAddressBookRef addressBook;
CFErrorRef error = NULL;
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) {
NSLog(@"saved..");
UIAlertView *alertOnChoose = [[UIAlertView alloc] initWithTitle:@"Phone added successfully to your addressbook" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertOnChoose show];
[alertOnChoose release];
}
if (error != NULL) {
NSLog(@"ABAddressBookSave %@", error);
UIAlertView *alertOnChoose = [[UIAlertView alloc] initWithTitle:@"Unable to save this time" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertOnChoose show];
[alertOnChoose release];
}
CFRelease(aRecord);
}
- 增加个人信息到通讯录
- 增加联系人到通讯录
- 个人信息:
- 个人信息
- 个人信息
- 个人信息
- 个人信息
- 个人信息
- 个人信息
- 个人信息
- 导通讯录,到小米
- iOS 保存到通讯录
- android实现对通讯录增加和查询
- 如何避免网站个人信息被搜索引擎搜到
- vb 中输入个人信息并保存到文档中
- 使用VB语言输入个人信息&保存到文档
- Android通讯录导入到Iphone
- 保存联系人到系统通讯录
- SHL测试题
- 你要做那种人
- Excel读取与创建方法三: MyXLS
- Mcafee 导致lotus notes NSD等错误
- 源代码下载网站(笔记!)
- 增加个人信息到通讯录
- 用两个栈实现一个队列
- DELPHI中引用sqlite3
- listview 使用 HashMap<String, SoftReference<Bitmap>> 时图片被过早地回收
- VS2008快捷键大全
- c#操作excel文件
- Java Mail开发问题---BASE64Encoder报错:"找不到该类所在的jar包!" 解决办法
- Excel读取与创建方法二:oledb
- 基于BP神经网络的字符识别研究(中文翻译)