Skip to content

Get image from iCloud on IOS #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mounirka opened this issue Jan 29, 2017 · 4 comments
Closed

Get image from iCloud on IOS #67

mounirka opened this issue Jan 29, 2017 · 4 comments
Labels

Comments

@mounirka
Copy link

Hi guys, the plugin is working perfectly on ios if the image that i want is locally saved in the device, but if i choose an image that i saved on my iCloud, the promise return without any data of the image.
Is there a workaround for this? Thank you.

@tsonevn
Copy link
Contributor

tsonevn commented Jan 30, 2017

Hi @mounirka,

For your case, you could use getImage() method for the selected item from the Cloud, which will return imageSource. then you should be able to use the image in your project. For further info and sample code, you could review the comment in this issue.

Hope this helps.

@mounirka
Copy link
Author

This is the code that i've been using and it still doesn't work with icloud

let context = imagepickerModule.create({
            mode: "single"
        });
        context
            .authorize()
            .then(function() {
                return context.present();
            })
            .then((selection) => {
                selection.forEach((selected) => {
                    selected.getImage().then((img) => {
                      this.cropper.show(img).then((args) => {
                              // Here i show the image to the user
                        })
                        .catch((e) => {
                            console.log("E: " + e.message());
                        });
                    },
                    (error) => {
                      console.log("getImage error", error);
                    }
                  );
                });
            }).catch(function (e) {
                console.log(e);
            });

@tsonevn
Copy link
Contributor

tsonevn commented Feb 1, 2017

Hi @mounirka,
I have tested your scenario while using nativescript-imagepicker and nativescript-imagecropper in a sample app.
To be able to use an image from a cloud, you should first save the image in a temporary file in the app as it has been shown in my previous comment. This has been related to the fact that, when you access such an image, there is no existing image Uri on the device.

When you save the image, you would also be able to use cropper show method.
For your convenience, I am attaching most important part of the code.

selection.forEach(function(selected_item) {
                selected_item.getImage().then(function(imagesource){
                    let folder = fs.knownFolders.documents();
                    let path = fs.path.join(folder.path, "Test"+counter+".png");
                    let saved = imagesource.saveToFile(path, "png");
                    if(saved){
                        var task = sendImages("Image"+counter+".png", path);
                        var item = new observable.Observable();
                        var cropper = new icModule.ImageCropper();
                        cropper.show(imagesource).then(function(args){
                        console.log(JSON.stringify(args));
                        if(args.image !== null){
                            // _image1.imageSource = args.image;
                                item.set("thumb", args.image);
                                item.set("uri", "Test"+counter+".png");
                                item.set("uploadTask", task);
                        }
                        
                        })

                        imageItems.push(item);
                    }
                    counter++;
                })
                
			});

The full project could be found here.

Hope this helps

@pap5508
Copy link

pap5508 commented Apr 3, 2017

@tsonevn : To select PDF and Word file stored on iCloud.. select it and call API..??

Do we have any sample code for that.. I do not need it for Image..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants