ihadeed / cordova-clipboard

Clipboard management plugin for Cordova/PhoneGap
MIT License
53 stars 42 forks source link

Can't access cordova.plugins.clipboard API only iOS. #13

Open yuto7th opened 4 years ago

yuto7th commented 4 years ago

Hi team! Thanks for your good products.

I want to paste text to use this plugin. Android OS worked well. But, iOS didn't work.

Error is here. TypeError: undefined is not an object ( evaluating 'cordova.plugins.clipboard')

It's impossible to access "cordova.plugins" to use only iOS. (Android is fine.) Please teach me how to resolve this problem.

wuori commented 4 years ago

Prefix with window, window.cordova.plugins.clipboard. Give that a try!

Martherius commented 2 years ago

Hi team! Thanks for your good products.

I want to paste text to use this plugin. Android OS worked well. But, iOS didn't work.

Error is here. TypeError: undefined is not an object ( evaluating 'cordova.plugins.clipboard')

It's impossible to access "cordova.plugins" to use only iOS. (Android is fine.) Please teach me how to resolve this problem.

I´m having a very similar problem, it works fine on Android, but on ios it does nothing, have you find any solution?

wuori commented 2 years ago

@Martherius Can you show me your code implementation for the clipboard call? I'm on a newer machine and don't have everything I need set up to debug at the moment.

Martherius commented 2 years ago

@Martherius Can you show me your code implementation for the clipboard call? I'm on a newer machine and don't have everything I need set up to debug at the moment.

This is the code on my controller.js im working on an ionic 1 app: $scope.copyText = function(value) { console.log(value); $cordovaClipboard.copy(value).then(function() { console.log(value + " copied to clipboard!"); $scope.showAlertExito("Copiado a portapapeles."); }, function() { console.error("Error. No se pudo copiar."); }); };

Then just call the method in the html template: `

Number to copy: {{number}}

        </div>`
wuori commented 2 years ago

@Martherius have you tried prefixing with window, like window.cordova.plugins.clipboard.copy(text);? Hopefully, I'll have my new machine setup and can test this out myself next week.

Martherius commented 2 years ago

@Martherius have you tried prefixing with window, like window.cordova.plugins.clipboard.copy(text);? Hopefully, I'll have my new machine setup and can test this out myself next week.

You mean instead of this:

$cordovaClipboard.copy(value)

I do this:

window.cordova.plugins.clipboard.copy(value)

ok thanks a lot this works for ios, although the notification does not show now

also this stopped working on android but i guess i just need to build android with option 1 and ios with option 2 Anyway thank you very much, been stuck with this for a while now.

also sorry to ask but i have one more issue with my app, i'm using com.darktalker.cordova.screenshot to take screenshots in the app and share them, works fine with iOS but for android works only on android 10 or less devices, android 11 and up it's not working anymore

wuori commented 2 years ago

@Martherius I'm glad you made some progress! I believe the same code worked for me on both iOS and Android.

I've only used this plugin atop a Vue-based Cordova application. You'll just want to make sure the code can access the plugin within its current scope.

I'm not familiar with the screenshot plugin, you may want to follow up by raising an issue with them.

FYI for anyone else reading this here's an example I had working (a year ago, at least) to copy a remote image to a clipboard:

    copyImage(url){

        return new Promise((resolve, reject) => {

            let folderpath = this.getSavePath();
            let filename = "Treet-Photo.png";

            window.cordova.plugin.http.downloadFile(url,null,null,folderpath+filename,(fileEntry) => {

                fileEntry.file( (file) => {

                    let reader = new FileReader();

                    reader.onloadend = function() {
                        // console.log("Successful file read: " + this.result);
                        window.cordova.plugins.clipboard.copy({
                            type: 'image',
                            data: this.result
                        }, (res) => {
                            resolve(res);
                        });
                    };

                    reader.readAsDataURL(file);

                }, (e) => { reject(e); } );

            }, (e) => { reject(e); });

        });

    },