我正在创建一个地址簿应用程序,因为所有数据都存储到服务器,当用户询问时,服务器会将所有联系人恢复到iPhone。
我的问题是如何将图像发送到服务器以及我将如何恢复联系人图像,我发现我的服务器将以base64加密格式提供给我一个图像。
所以可以帮助我如何以编程方式执行图像保存和检索地址簿
答案 0 :(得分:5)
您需要在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);