Search code examples
iosiphoneobjective-cuiimageabaddressbook

How to get the contact image URL from contacts?


I need to get the image url for each contact from AddressBook. I can get the image now, but the thing is I need to get the asset URL of the image for the particular person. Currently I'm getting the contact image by

[UIImage imageWithData:(__bridge NSData *)ABPersonCopyImageData(person)]

Please help me to get the asset URL for that particular image. Thanks


Solution

  • I think you need to make a local copy of the data, and then save a refereance to that local copy in your database:

    //create a fileName perhaps based on the contact name or a GUID
        NSError *err;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);//find the cache dir. You might want to consider using the doc dir instead
        NSString * path = [paths  objectAtIndex:0];
        path = [path stringByAppendingPathComponent:fileName];
       [imgData writeToFile:path options:NSDataWritingAtomic error:&err];
       if(!err)
       {
       ///save path to the DB
       }