Smile-SA / cordova-plugin-fileopener

24 stars 28 forks source link

Cordova 6.0.0 compatibility #9

Closed skar3 closed 8 years ago

skar3 commented 8 years ago

Hi, after cordova update to version 6.0.0 the plugin does not open urls that can be opened from my system, in particular when a jpg file is opened:

I/chromium: [INFO:CONSOLE(312)] "Error in Success callbackId: FileOpener135459028 ReferenceError: url is not defined", source: file:///android_asset/www/cordova.js (312)

before upgrading cordova I had no problems

my code:

   var onSuccess = function(data) {
        alert('message: ' + data.message);
    };

    function onError(error) {
        function alertDismissed() {
            // do something
        }

        navigator.notification.alert(
            error.message,  // message
            alertDismissed,         // callback
            'Attenzione',            // title
            'Ok'                  // buttonName
        );
    }

    var onTrySuccess = function(data) {
        if (data.canBeOpen) {
            window.cordova.plugins.FileOpener.openFile(url, onSuccess, onError);
        }else {
            function alertDismissed() {
                // do something
            }

            navigator.notification.alert(
                'Non è possibile aprire i file con estensione ' + data.extension + '.\nScarica un applicazione in grado di farlo.',  // message
                alertDismissed,         // callback
                'Attenzione',            // title
                'Ok'                  // buttonName
            );
        }
    };

    function onTryError(error) {
        function alertDismissed() {
            // do something
        }

        navigator.notification.alert(
            error.message,  // message
            alertDismissed,         // callback
            'Attenzione',            // title
            'Ok'                  // buttonName
        );
    }

    $('.attachment-list-url').click(function() {
        var url = "http://www.site.it/wp-content/uploads/2015/03/image.jpg"
        alert(url);
        window.cordova.plugins.FileOpener.canOpenFile(url, onTrySuccess, onTryError);
    });
marob commented 8 years ago

Hi,

it's not a cordova version related problem, but rather a problem in your code.

The url variable is defined inside the callback function of the .click and is therefore not available outside of this scope. If you move the var url = ... declaration one line above (before the $('.attachment-list-url').click(function() { line), the url variable will be defined in your onTrySuccess callback.

Note that your url points to a 404, so it will not be downloaded either way...

Regards

skar3 commented 8 years ago

Hi, thank you, the URL it's an example site :)

Il giorno gio 18 feb 2016 19:53 Maxime Robert notifications@github.com ha scritto:

Hi,

it's not a cordova version related problem, but rather a problem in your code.

The url variable is defined inside the callback function of the .click and is therefore not available outside of this scope. If you move the var url = ... declaration one line above (before the $('.attachment-list-url').click(function() { line), the url variable will be defined in your onTrySuccess callback.

Note that your url points to a 404, so it will not be downloaded either way...

Regards

— Reply to this email directly or view it on GitHub https://github.com/Smile-SA/cordova-plugin-fileopener/issues/9#issuecomment-185858069 .