答案 0 :(得分:15)
答案 1 :(得分:14)
以下是在Iphone地址簿中添加与人物形象联系的代码
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();
NSData *dataRef = UIImagePNGRepresentation(personImageView.image);
ABPersonSetImageData(person, (CFDataRef)dataRef, nil);
CFErrorRef anError = NULL;
ABRecordSetValue(person,kABPersonFirstNameProperty,full_name,&anError);
ABRecordSetValue(person, kABPersonOrganizationProperty, companyLabel, &anError);
ABRecordSetValue(person, kABPersonJobTitleProperty, designation, &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, addressDictionary, (CFStringRef)@"Address", NULL);
ABRecordSetValue(person, kABPersonAddressProperty, multiAddress,&anError);
CFRelease(multiAddress);
ABMutableMultiValueRef websiteMultiValue = ABMultiValueCreateMutable(kABPersonURLProperty);
ABMultiValueAddValueAndLabel(websiteMultiValue, web_URL, (CFStringRef)@"Website", NULL);
ABRecordSetValue(person, kABPersonURLProperty, websiteMultiValue, &anError);
ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABPersonEmailProperty);
ABMultiValueAddValueAndLabel(emailMultiValue, email, (CFStringRef)@"Email", NULL);
ABRecordSetValue(person, kABPersonEmailProperty, emailMultiValue, &anError);
ABAddressBookAddRecord(addressBook, person, &anError);
答案 2 :(得分:1)
如果有人正在寻找在Swift中添加地址详细信息(街道,城市,州,邮政编码)的方法,那么Apple的网站上没有详细记录。这是我做的方式(只有示例中显示的地址详细信息)...
var addressDictionary: [String:String] = [
kABPersonAddressStreetKey as String: Contact.address_1,
kABPersonAddressCityKey as String: Contact.city,
kABPersonAddressStateKey as String: Contact.state,
kABPersonAddressZIPKey as String: Contact.zip
]
let multiWork: ABMutableMultiValue =
ABMultiValueCreateMutable(
ABPropertyType(kABMultiDictionaryPropertyType)).takeRetainedValue()
ABMultiValueAddValueAndLabel(multiWork, addressDictionary, kABWorkLabel, nil)
ABRecordSetValue(person, kABPersonAddressProperty, multiWork, nil)