Selecting an image on iOS. PHAsset returned instead of file location or image source

images

#1

Hi,
I’m converting my Android application to iOS and ran into an error when selecting an image from the device library. To pick the image I use NativeScript Image Picker and the following code:

var context = imagepicker.create({ mode: "single" });
    context.authorize()
    .then(function() {
        return context.present();
    })
    .then(function(selection) {
        selection.forEach(function(selected) {
            var imageFromLocalFile;
            if(application.ios){
                imageFromLocalFile = imageSourceModule.fromFile(selected["_ios"]);
            } else if (application.android){
                imageFromLocalFile = imageSourceModule.fromFile(selected["_android"]);
            }
            console.log(imageFromLocalFile);
            settings.contactPhoto = imageFromLocalFile.toBase64String("png");
            saveSettings();
            updateContactImage();
        });
    }).catch(function (e) {
        console.log("imageTap error: " + e);
    });

On Android imageFromLocalFile would return “/storage/emulated/0/Pictures/Screenshots/Screenshot_20180729-175453.jpg”.

On iOS however I get this:

<PHAsset: 0x7faeeee97150> ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED/L0/001 mediaType=1/0, sourceType=1, (3000x2002), creationDate=2012-08-08 21:55:30 +0000, location=1, hidden=0, favorite=0

I’ve looked around but can’t find a clear or up to date answer. How do I turn this string (I assume it’s and PHAsset?) into a file location and ultimately an image source?

Any help is greatly appreciated, thanks in advance!


#2

It’s not a issue, simply that is how iOS works. If you want to retrieve file path, you will have to access PHAsset apis.


#3

How would I do this? I didn’t find an answer that figured it out yet.