Skip to content
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

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

Open
yuto7th opened this issue May 18, 2020 · 7 comments
Open

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

yuto7th opened this issue May 18, 2020 · 7 comments

Comments

@yuto7th
Copy link

yuto7th commented May 18, 2020

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
Copy link

wuori commented Oct 23, 2020

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

@Martherius
Copy link

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
Copy link

wuori commented Jan 19, 2022

@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
Copy link

@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:
<div class="text" ng-if="titboton == 'B'" ng-cloak> Number to copy: {{number}} <button class="buttoncopy" ng-show="showbutton == 1" type="button" ng-click="copyText(number)"> <i class='icon ion-ios-copy'></i> </button> </div>

@wuori
Copy link

wuori commented Jan 21, 2022

@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
Copy link

Martherius commented Jan 21, 2022

@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
Copy link

wuori commented Jan 24, 2022

@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); });

        });

    },

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

No branches or pull requests

3 participants