cordova-plugin-photo-library icon indicating copy to clipboard operation
cordova-plugin-photo-library copied to clipboard

Issue in saving image when "iCloud Photo Library" is "ON" in settings in iOS 11

Open leftdead7 opened this issue 7 years ago • 14 comments

Getting "Retrieved asset is nil" in failure callback when i am trying to save a image when "iCloud Photo Library" setting is turned ON . When i turn off the setting i am unable to save the image well. The plugin was working really well till iOS 10.3 . Please suggest if i need to do any changes for "iCloud Photo Library"

leftdead7 avatar Oct 06 '17 05:10 leftdead7

Sorry

The image is getting saved in the device, but still i am getting "Retrieved asset is nil" in error callback

I actually do not need the item back after saving the image to gallery, so can i safely ignore this error?

leftdead7 avatar Oct 06 '17 06:10 leftdead7

I am seeing the same issue with iOS 11.

jayordway avatar Oct 22 '17 03:10 jayordway

Same here with iOS 11, disabled iCloud Photo Library and it works know

bytestack avatar Oct 26 '17 21:10 bytestack

Also seeing this.

mikewagz avatar Nov 08 '17 19:11 mikewagz

I'm having this issue as well, and will do my best to be able to resolve it (even if I'm not very good at native development) 😅

This actually worked fine while iOS 11.0 was in beta (and maybe even the GM, but I'm not quite sure about that). I will have a look if there was any changes made to the Gallery API during the beta phase.

gildebrand avatar Nov 09 '17 13:11 gildebrand

Could it be a race condition somewhere? Because sometimes it works. Also when the exception occurs, the image is not added to the album with the name given in saveImage(). But in either case the image shows up in "All Photos". (Tested on iOS 11.1.1)

nharrer avatar Nov 13 '17 20:11 nharrer

@nharrer did you find any solution?

mubasshir avatar Dec 16 '17 13:12 mubasshir

@mubasshir no, unfortunately not. Thankfully it's not a complete show stopper, since the pictures show up in "All Photos". And I can also confirm that it starts working once iCloud Photo Library is turned off (which is not an option for my customers though).

nharrer avatar Dec 16 '17 14:12 nharrer

I guess I will hardcode and display success message if this particular error occurs

mubasshir avatar Dec 24 '17 05:12 mubasshir

Hey guys, Anyone could solve this? I don't have any more ideas or workarounds here :/

thanks!

endani avatar Feb 09 '18 12:02 endani

The issue is discussed here: https://stackoverflow.com/questions/26480526/alassetslibrary-assetforurl-always-returning-nil-for-photos-in-my-photo-stream

The comment by Thomas Hilbert seems to explain the bug in the plugin:

I've made the observation that trying to retrieve an asset using assetForURL inside a writeImage toSavedPhotosAlbum success block for that same asset will yield an asset of nil (most of the time).

However, retrieving the asset with assetForURL some time after the writeImage success block has completed execution does yield the correct asset.

I tried his solution and added a sleep(1) inside saveImage(), just before the self.putMediaToAlbum() call. It seems to fix the issue, at least for me.

This fix is not very clean: I doubt calling sleep() is a good practice, and the 1 second delay will probably be too much or too little depending on the context.
I don't have enough swift knowledge to write this, but it looks like an acceptable workaround would be to write a loop that calls asset() every 100ms until it returns something else than nil (with a timeout after a few unsuccessful calls).

Saturnyn avatar Apr 03 '18 12:04 Saturnyn

Issue is still present :(

ghost avatar Jul 03 '18 15:07 ghost

i make a pull request to resove this issue, see #141

jasonz1987 avatar Jul 30 '18 17:07 jasonz1987

image Just sleep it!!!

zhzhch335 avatar Aug 22 '18 03:08 zhzhch335