0

I am new to iPhone application development. My application has its own contact screen which has all contacts of phone book and also application's contacts in single list. My application should store all contacts in its dataabse, it should not display contact screen like contact picker opens. For this I have created entity of contact to store contacts in my application's persistent store. I have read iphone's contacts using AddessBook APIs. I am facing some problems in that.

  1. Problem in storing contact image : To get contact image I have used ABPersonCopyImageData. It returns CFDataRef. How can we store CFDataRef in database and retrieve it. Because there are only primitive data types available in entity's attribute type (NSArry type is not available).

  2. Problem in storing Multivalue Properties : If any any contact has multiple numbers, then we received multiple value for number. Is there any API or mechanism available in core data ? or we have to store them using custom mechanism like using delimiter.

Khushbu Shah
  • 1,603
  • 3
  • 27
  • 45
  • if talking about NSUserDefaults, you are able to store images converted to NSData or base64 strings. also, isn't the "number" property actually an array of numbers? – John Smith May 02 '13 at 06:35

2 Answers2

1

if I was you then i would be storing images in document directory convert CFDataRef into NSData and then UIImage you can convert CFDataRef to NSData simply like this

NSData *myData = (NSData *)myCFDataRef;

then convert it to UIImage like this

UIImage *image=[UIImage imageWithData:myData];

and store it in document directory with different name like test_1.png where 1 is intiger which you increment every time for new image name

and in database store only location string

Prakash Desai
  • 511
  • 3
  • 14
0

Problem 1:- You can convert CFDataRef to UIImage and store that in database using datatype "Transformable"

Problem 2:- You have to save that using any delimeter or you can create different attributes for that.

Hope this help you.

LittleIDev
  • 921
  • 6
  • 7
  • I cannot create different attributes for that because a contact has any number of contact number for different labels. Is this possible using relationship of core data? – Khushbu Shah May 02 '13 at 06:47
  • ya you can create a relationship to another entity and can store all the contact numbers in that entity. – LittleIDev May 02 '13 at 07:05
  • Can you give any link or example for your solution of problem 1. – Khushbu Shah May 02 '13 at 12:47
  • NSData *dataObj = (NSData *)CFDataRefObj; UIImage *imageObj=[UIImage imageWithData:dataObj]; or you can refer [link](http://stackoverflow.com/questions/3801706/how-to-convert-cfdataref-into-nsdata). After that just store the "imageObj" in your respected entity using datatype "Transformable". – LittleIDev May 03 '13 at 04:59
  • For storing UIImage you can refer the sample code [link](https://github.com/blackpixel/NSConferenceiPhoneCoreDataRecipes).Hope it helps you. – LittleIDev May 03 '13 at 05:07