地址簿以编程方式保存联系人图像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了地址簿以编程方式保存联系人图像相关的知识,希望对你有一定的参考价值。
我正在创建一个地址簿应用程序,因为所有数据都存储到服务器,当用户询问时,服务器会将所有联系人恢复到iPhone。
我的问题是如何将图像发送到服务器以及我将如何恢复联系人图像,我发现我的服务器将为我提供base64加密格式的图像。
所以可以帮助我如何以编程方式执行图像保存和检索Addressbook
答案
您需要在nsdata中转换base64图像,然后将其设置为联系人,请在以下代码中选中“ABPersonSetImageData”。
ABRecordSetValue(newPerson, kABPersonOrganizationProperty,data.name, &error);
ABMutableMultiValueRef multiURL = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiURL, homePageURL, kABPersonHomePageLabel, NULL);
ABRecordSetValue(newPerson, kABPersonURLProperty, multiURL,&error);
CFRelease(multiURL);
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, contactNumber, kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,&error);
CFRelease(multiPhone);
ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail, emailIDs, kABHomeLabel, NULL);
ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error);
CFRelease(multiEmail);
ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
[addressDictionary setObject:toAddress forKey:(NSString *) kABPersonAddressStreetKey];
[addressDictionary setObject:@"Amsterdam" forKey:(NSString *) kABPersonAddressCityKey];
[addressDictionary setObject:@"Amsterdam" forKey:(NSString *) kABPersonAddressStateKey];
[addressDictionary setObject:@"00000" forKey:(NSString *) kABPersonAddressZIPKey];
[addressDictionary setObject:@"Netharland" forKey:(NSString *) kABPersonAddressCountryKey];
ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABHomeLabel, NULL);
ABRecordSetValue(newPerson, kABPersonAddressProperty, multiAddress,&error);
CFRelease(multiAddress);
NSData *data1 = UIImagePNGRepresentation([UIImage imageNamed:data.titleImg]);
ABPersonSetImageData(newPerson, data1, &error);
ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
ABAddressBookSave(iPhoneAddressBook, &error);
以上是关于地址簿以编程方式保存联系人图像的主要内容,如果未能解决你的问题,请参考以下文章
如何在以编程方式将 newInsert 插入地址簿后获取最后插入的 RawContacts ID?