question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IOS : Selected image is empty

See original GitHub issue

Which platform(s) does your issue occur on?

  • iOS
  • emulator or device. What type of device? Tested on :
  • IOS 10.2 on iPhone 6
  • IOS 11.4 on iPhine 8 Plus

Please, provide the following version numbers that your issue occurs with:

  • CLI: (run tns --version to fetch it) 4.1.1
  • Cross-platform modules: (check the ‘version’ attribute in the node_modules/tns-core-modules/package.json file in your project)

“tns-core-modules”: “^4.1.0”,

  • Runtime(s): (look for the "tns-android" and "tns-ios" properties in the package.json file of your project)

“tns-android”: { “version”: “4.1.3” }, “tns-ios”: { “version”: “4.1.1” }

  • Plugin(s): (look for the version numbers in the package.json file of your project and paste your dependencies and devDependencies here)

“devDependencies”: { “babel-traverse”: “6.26.0”, “babel-types”: “6.26.0”, “babylon”: “6.18.0”, “lazy”: “1.0.11”, “nativescript-dev-typescript”: “^0.7.1”, “typescript”: “~2.6.2” }

Please, tell us how to recreate the issue in as much detail as possible.

Describe the steps to reproduce it.

I use your code with onSelectSingleTap method :

private startSelection(context) {
        context
            .authorize()
            .then(() => {
                this.imageAssets = [];
                this.imageSrc = null;
                return context.present();
            })
            .then((selection) => {
                console.log("Selection done: " + JSON.stringify(selection));
                this.imageSrc = this.isSingleMode && selection.length > 0 ? selection[0] : null;

                // set the images to be loaded from the assets with optimal sizes (optimize memory usage)
                selection.forEach(element => {
                    element.options.width = this.isSingleMode ? this.previewSize : this.thumbSize;
                    element.options.height = this.isSingleMode ? this.previewSize : this.thumbSize;
                });

                this.imageAssets = selection;
            }).catch(function (e) {
                console.log(e);
            });
    }

Is there any code involved?

  • provide a code example to recreate the problem
  • (EVEN BETTER) provide a .zip with application or refer to a repository with application where the problem is reproducible.

On IOS i get this after select image :

[{"_observers":{},"_options":{"keepAspectRatio":true},"_ios":{}}]

It work fine on android

Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

4reactions
NevinDrycommented, Jun 27, 2018

Hi,

I have done some research on this issue, and here is how I fixed it

pickFile() {
        const that = this;
        that.context
            .authorize()
            .then(function () {
                return that.context.present();
            })
            .then(function (selection) {
                selection.forEach(function (selected) {
                    let file;
                    if (selected._android) {
                        file = fileSystemModule.File.fromPath(selected._android);
                        that.uploadFile(file);
                    }else{
                        imageSourceModule.fromAsset(selected).then((imageSource) => {

                        const folder = fileSystemModule.knownFolders.documents().path;
                        const fileName = "test.png"; 
                        const path = fileSystemModule.path.join(folder, fileName);
                        const saved = imageSource.saveToFile(path, "png");
                        if (saved) {
                            console.log("Image saved successfully!");
                            file = fileSystemModule.File.fromPath(path);
                            that.uploadFile(file);
                        }else{
                            //process error
                        }
                    });
                }
            });
            }).catch(function (e) {
                console.log(e);
                // process error
            });

You can see that first, I use the TNS imageSourceModule so don’t forget to declare it at the top.

const imageSourceModule = require("tns-core-modules/image-source");

I use the fromAsset function directly on the “selected” because apparently with the new version of this plugin, “selected” is an Asset. So you got an imageSource and you can use the “saveToFile” function that will copy the Asset into a new location (get this location using fileSystemModule from TNS). Use the path of this new location for your UI, and the image will appear. You can also create a file object from this location ( fileSystemModule.File.fromPath(path); ), I use for upload.

I can help if you need more information.

3reactions
skmanicommented, Oct 27, 2020

i am also having the same issue any fixes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My iPhone 5 camera roll is empty, but und… - Apple Community
Open it, "Select" and start deleting; Now, go back into Settings - General - Usage - Storage - Manage Storage - and you'll...
Read more >
Selecting photo returns to blank UI - Stack Overflow
The first thing I am trying to do is enable the user to select an image that they want for upload. EDIT 6....
Read more >
image_picker | Flutter Package - Pub.dev
Flutter plugin for selecting images from the Android and iOS image library, and taking new pictures with the camera.
Read more >
Crop images in Photoshop Elements - Adobe Support
To select a crop ratio other than that of the original photo, ... Crops the image to remove any blank background area that...
Read more >
Empty .MOV file, stuck on iPhone - Ask Different
The movie plays normally in Preview.app on the Mac. I cannot select the file in Image Capture, so I cannot click the Delete...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found