0

试图允许用户将我的应用程序中的联系方式保存到他们的通讯录/联系人中。

在 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 图像没有重复连接等。

一如既往的任何建议

4

2 回答 2

1

ABAddressBookSave()

http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABAddressBookRef_iPhoneOS/Reference/reference.html

Re your image problem, it looks like you are passing a UIImageView instance to UIImagePNGRepresentation() rather than a UIImage instance

于 2012-07-17T18:09:52.290 回答
0

Ok sorted the no action problem, had to implement the code to present the view!

于 2012-07-17T19:28:40.540 回答