Clipboard and Local Notifications plugins not working

Hello everyone !

I started Ionic v2 a week ago and I now need to use the clipboard plugin (https://ionicframework.com/docs/native/clipboard/) and the Local notifications plugin (https://ionicframework.com/docs/native/local-notifications/).

First at all, I installed them by running the right commands as shown in the tutorial, then I imported them to my app.module.ts and referred them in the providers list.

After this, I imported them as well in my home.ts or in my notif-modal.ts and added them to the constructor parameters.

But then, when I want to use them, it doesn’t work …

I noticed that I don’t have the plugin line for local notifications in config.xml, but I do have the clipboard one :

<plugin name="com.danielsogl.cordova.clipboard" spec="~1.0.2" />

Here is my codes, do someone have any idea ?

Here is app.module.ts :

...
import { Clipboard } from '@ionic-native/clipboard';
import { LocalNotifications } from '@ionic-native/local-notifications';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
   ...
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    ...
  ],
  providers: [
    ...
    LocalNotifications,
    Clipboard
  ]
})

Then my notif-modal.ts (to set the notifications) :

...
import { LocalNotifications } from '@ionic-native/local-notifications';

/**
 * Generated class for the NotifModalPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-notif-modal',
  templateUrl: 'notif-modal.html',
})
export class NotifModalPage {
  
  constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl: ViewController, public platform: Platform, public localNotifications: LocalNotifications) {  
    platform.ready().then(() => {
        platform.registerBackButtonAction(() => {
          this.viewCtrl.dismiss();
        });
      });
    }

  closeModal() {
    let firstNotificationTime = new Date();
    firstNotificationTime.setMinutes(firstNotificationTime.getMinutes() + 1);
    this.localNotifications.schedule({
        id: 1,
        title: 'Hey!',
        text: 'You just got notified :)',
        at: firstNotificationTime
    });
    
    this.viewCtrl.dismiss();
  }
}

As you can see, I just try to set a SIMPLE notification, with a fixed ID, fixed title, fixed text, and the actual data plus one minute …

Next, for the clipboard plugin, here is the interesting part of home.ts :

...
 import { Clipboard } from '@ionic-native/clipboard';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {

  constructor(public navCtrl: NavController, public modalCtrl: ModalController, private keyboard: Keyboard, public alertCtrl: AlertController, public storage: Storage, private clipboard: Clipboard) {

  }

export() {
this.clipboard.copy("hello");
      let alert = this.alertCtrl.create({
        title: 'Copied !',
        subTitle: 'Copy done !',
        buttons: ['Ok']
      });
      alert.present();
    });
  }
}

The alert pop up, but still, if I try to paste somewhere I don’t have anything in my clipboard…

Thanks for those who will be able to help, that’s the last step of my application :smiley:

This is not a good problem description. Does “nothing” happen? Do you get an error?

What is your ionic info output?

First of all, thanks for your reply !

Yeah sorry, I explain myself : For the notification plugin, the notification doesn’t popup. For the clipboard plugin issue, I get nothing in my phone clipboard.

Here ismy ionic info :

global packages:

    @ionic/cli-utils : 1.5.0
    Cordova CLI      : 7.0.1
    Ionic CLI        : 3.5.0

local packages:

    @ionic/app-scripts              : 2.0.0
    @ionic/cli-plugin-cordova       : 1.4.1
    @ionic/cli-plugin-ionic-angular : 1.3.2
    Cordova Platforms               : android 6.2.3
    Ionic Framework                 : ionic-angular 3.5.0

System:

    Node       : v8.1.3
    OS         : Windows 8.1
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed
    npm        : 5.0.3

Please seperate your problems. Create a new project (ionic start blank blank) and only implement one plugins functionality. If this still doesn’t work, upload the project to Github and show us. If it does work, you just solved your problem - compare the relevant parts of the projects.

Ok so here is what I did, I began with the clipboard plugin :

 ionic start blank blank
cd blank
ionic cordova plugin add danielsogl-cordova-plugin-clipboard
npm install --save @ionic-native/clipboard

Then I added the import of the clipboard to the app.module.ts :

import { Clipboard } from '@ionic-native/clipboard';

and

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    Clipboard
  ]
})

Finally, I added again

import { Clipboard } from '@ionic-native/clipboard';

to my home.ts and I added

private clipboard: Clipboard

to my constructor.

Then I created a simple button to launch a function to copy some text :

 copyToClipboard() {
      this.clipboard.copy("COPYTHISTOCLIPBOARD");
  }

<button ion-button (click)="copyToClipboard()">COPY TO CLIPBOARD</button>

Then I did build the application, loaded on my phone, clicked the button, my clipboard didn’t changed, I mean, I had the same thing as before clicking the button …

Here is the git where I uploaded it : https://github.com/iskydive/ClipboardCordovaPluginBug

For the notifications :

 ionic start blank blank
cd blank
ionic cordova plugin add de.appplant.cordova.plugin.local-notification
npm install --save @ionic-native/local-notifications

Then I added the import of the clipboard to the app.module.ts :

import { LocalNotifications } from '@ionic-native/local-notifications';

and

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    LocalNotifications
  ]
})

Finally, I added again

import { LocalNotifications } from '@ionic-native/local-notifications';

to my home.ts and I added

private localNotifications: LocalNotifications

to my constructor.

Then I created a simple button to set a simple notification :

 setNotification() {
      this.localNotifications.schedule({
        id: 1,
        title: 'Hello !',
        text: 'Single ILocalNotification',
        at: new Date(new Date().getTime() + 5 * 1000)
      });
  }
  }

<button ion-button (click)="setNotification()">SET NOTIFICATION</button>

Then I did build the application and I got an error when “cordova platform add --save android”, it failed to install the local notification plugin …

Here is the git where I uploaded it : https://github.com/iskydive/LocalNotificationPluginBug

Clipboard plugin is buggy right now, so I can’t work with the repository as it is. I created fix Cordova plugin ID by janpio · Pull Request #3 · danielsogl/cordova-plugin-clipboard · GitHub to fix this. But this shouldn’t affect you if you just installed it locally.

But I just saw that on ionic-native the repo URL was changed anyway, so I just used this one (not yet published in the docs) and then… it still doesn’t work. Meh.

The second repo you linked to is actually missing the Android platform. Adding it is not possible because of the local notification plugin. This is because it also mixes plugin id and package id…

Sorry, I can’t really help you here. Stuff really seems to be broken with both plugins here.

So, if I understand well, for now I can’t make any one of those working?

And you made 2 requests for the clipboard plug-in and if, they accept it, I will be able to download it again and make it work or can I already?

And since I don’t know enough to make a request for the local notifications, can’t somebody make it so they fix it?

No, it just means I couldn’t make it work as well.

Not really, ionic native changed something already that is not published to the docs yet, but even with this I can’t make it work.

If you don’t get any better answers here I think you should create two issues with Ionic Native and link to them here. Maybe someone else can look into it. (Ionic Native is mostly community overseen)

Oh okay…

Ok and where can I create those issues with Ionic Native?

I already posted this one in the native category

This is “only” the community forum. Actual problems with the code are created as issues on Github: https://github.com/ionic-team/ionic-native/issues

Thank you, I opened issues on the git

Please post links to them here so we can follow them.

For the clipboard plugin I finally used clipboard.js. It is very simple, here is a tutorial : https://clipboardjs.com/

For the notifications, here is the link : https://github.com/ionic-team/ionic-native/issues/1819

1 Like