尝试允许用户将我的应用中的联系人详细信息保存到地址簿/联系人。
在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);
}
我已导入
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI>.h
当我按下按钮时,我完全没有回应。什么都没发生。只是提到这是我第一次尝试使用地址簿框架,如果这是一个明显的错误。
我还想用以下
保存联系人照片 NSData *dataRef = UIImagePNGRepresentation(my image here);
ABPersonSetImageData(person, (__bridge_retained CFDataRef)dataRef, nil);
然而,我得到一个异常抛出,我以一种因果方式判断图像,不确定这是否适合这种方法?收到错误消息:
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'
通常,当由于连接问题引发异常时,我已经进行了双重检查,并且UI图像没有重复的连接等。
任何建议一如既往地赞赏
答案 0 :(得分:1)
ABAddressBookSave()
重新解决您的图像问题,看起来您正在将UIImageView实例传递给UIImagePNGRepresentation()而不是UIImage实例
答案 1 :(得分:0)
确定排序无操作问题,必须实现代码才能显示视图!