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

[ionic-native 3.4.2] TypeError: plugin.constructor.getPluginRef is not a function #1297

Closed
azakusilo opened this issue Mar 29, 2017 · 2 comments

Comments

@azakusilo
Copy link

azakusilo commented Mar 29, 2017

Hello I wrote a wrapper for ionic native push plugin. But after the App is starts. It's get a error TypeError: plugin.constructor.getPluginRef is not a function.
Here is a code of my wrapper:

import { Injectable } from "@angular/core";
import {
  Push, PushObject, PushOptions, EventResponse, NotificationEventResponse,
  RegistrationEventResponse
} from '@ionic-native/push';
import { Events, ToastController, Platform, App, NavController } from "ionic-angular";
import { Device } from "ionic-native";
import { APP_CONFIG } from "../app/app.config";
/**
 * Класс сервиса для управления PUSH уведомлениями
 */
@Injectable()
export class PushNotificationService {
  register_token_url = '/api/methods/push.registerToken';
  pushNotification: PushObject; //Notification's API
  push_token = "";
  messages_stack_id = []; //Messages stack


  /**
   * Constructor of class
   *
   */
  constructor(
    public plt: Platform,
    public toastCtrl: ToastController,
    public appCtrl: App,
    public httpRequestService: HttpRequestService,
    public authService: AuthService,
    public events: Events,
    public push: Push
  ){

  }

  /**
   * Initialization
   */
  init()
  {
     let pushSenderID = APP_CONFIG.pushSenderID.toString();
     if (pushSenderID.length) { //If we have sender id

       const options: PushOptions = {
         android: {
           sound: true,
           vibrate: true,
           forceShow: false,
           senderID: pushSenderID
         },
         ios: {
           alert: true,
           badge: true,
           sound: true,
           gcmSandbox: true,
           senderID: pushSenderID
         },
         windows: {}
       };

       this.pushNotification = this.push.init(options);

       //Check the rights
       if (this.plt.is('ios') || this.plt.is('android')) {
         this.pushNotification.hasPermission().then((isEnabled) => { //If we get push rights
           if (!isEnabled){
             this.showToast('No right to get push notify.');
           }else{
             console.log('We have PUSH permission!');
           }
         }).catch((reason) => {
           this.showToast('No right to get push notify: ' + reason.toString()); //Here is a error
         });
       }

       //Registration of token
       this.pushNotification.on('registration').subscribe((data: RegistrationEventResponse) => {
         this.onRegistrationToken(data);
       });

       //Get Notification
       this.pushNotification.on('notification').subscribe((data: NotificationEventResponse) => {
         this.onNotification(data);
       });


       //Get errors
       this.pushNotification.on('error').subscribe((e: Error) => {
         console.error(e.message);
         this.showToast("PUSH Error: " + e.message);
       });
     }
  }
}

I got lastest installed packeges:

    "@ionic-native/core": "^3.4.2",
    "@ionic-native/push": "^3.4.2",
@azakusilo
Copy link
Author

azakusilo commented Mar 30, 2017

I updated my package but still have the same error in the same place of code on check hasPermission

@ihadeed
Copy link
Collaborator

ihadeed commented Mar 30, 2017

@azakusilo just updated the push plugin.

hasPermission should be part of the Push class and not PushObject.

Correct usage is:

this.push.hasPermission()
  .then(res => console.log('Has permission?', res.isEnabled);

Update @ionic-native/push to 3.4.4.

ihadeed added a commit that referenced this issue Mar 30, 2017
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

2 participants