地址簿以图书的形式保存联系人图像 [英] Addressbook Save Image for contacts Programatically

查看:103
本文介绍了地址簿以图书的形式保存联系人图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个地址簿应用程序,因为所有数据都存储到服务器,当用户询问时,服务器会将所有联系人恢复到iPhone。

I am creating an addressbook application in that all the data are stored to server and when User will ask then server will restore all the contacts to iPhone.

我的问题是如何将图像发送到服务器以及我将如何恢复联系人图像,我知道我的服务器将为我提供base64加密格式的图像。

My problem is how to send Image to server as well as how I will be able to restore the contact Image , I came to know that my server will provide me an Image in base64 encryption formate.

所以可以帮助我如何以编程方式执行图像保存和检索地址簿

So can any help me how to perform image saving and retrieving for Addressbook Programatically

在此先感谢

推荐答案

您需要在nsdata中转换base64图像,然后将其设置为联系人,请在以下代码中选中ABPersonSetImageData。

You need to convert the base64 image in nsdata and then you can set it to a contact, check "ABPersonSetImageData" in following code.

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);

这篇关于地址簿以图书的形式保存联系人图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆