rt2zz / react-native-addressbook

React Native AddressBook
82 stars 13 forks source link

Thumbnail path errors out #6

Closed AdamBrodzinski closed 9 years ago

AdamBrodzinski commented 9 years ago

When I save the thumbnail path to local storage and then re-build the app the image no longer works (errors out with " Unrecognized tag protocol").

Am I doing something wrong or will it be ok on phones that are not being constantly re-built? I wasn't sure if I had to manually save the photo from the thumbnailPath from the address book.

rt2zz commented 9 years ago

hmm, I am not sure actually. It could be a few things, let me make sure I understand the situation:

You are getting the thumbnail path from the records returned in getContacts. You are then saving that path using AsyncStorage. Then you are trying to display and image using that stored thumbnail path.

Is this correct?

AdamBrodzinski commented 9 years ago

You are getting the thumbnail path from the records returned in getContacts. You are then saving that path using AsyncStorage. Then you are trying to display and image using that stored thumbnail path.

Is this correct?

Yep! Sorry for not being as clear as I could have. Basically when the user adds a contact from the contacts book, the contact object is saved in local storage (under a recent contacts key). The path url is used for the avatar picture and this works great until the app is re-built... then no image is shown and the error is thrown.

The workaround is to re-add the contact by opening up the contacts book.... then it works for that session.

It seems like perhaps this path is temporary? The image is still in the iOS contacts book after re-building as well.

Thanks!!

AdamBrodzinski commented 9 years ago

Here's the complete error:

Error setting property 'imageTag' of RCTStaticImage with tag #56: Unrecognized tag protocol: /Users/adam/Library/Developer/CoreSimulator/Devices/3E63D804-8618-4AF6-8ECA-E6BDBDD06FF7/data/Containers/Data/Application/8FEAB92C-1B64-4CEA-AD7A-68C44B3BF610/tmp/thumbimage_NaeUT
rt2zz commented 9 years ago

Ah, yes I believe the tmp directories are cleaned up periodically, including likely upon recompile. Possible options:

  1. Load the address book fresh every time
  2. Load the thumbnail as base64 using https://github.com/johanneslumpe/react-native-fs and then store that instead of the temporary path

Looking at the ios addressbook documentation I do not believe there is a way to get a permanent file path to the image. But let me know if you find out otherwise.

AdamBrodzinski commented 9 years ago

Oh ok that makes sense. I'll just pull all of the contacts on load if there's permission and re-save all the thumbnails from the app's 'recent contacts' list. That should also catch any photos that are updated/removed in the mean time as well.

Thanks!