rashadb
rashadb

Reputation: 2543

How do I utilize the Parse push plugin in an Ionic 2 app?

I'm trying to use the Parse push plugin with my Ionic 2 app from: https://github.com/taivo/parse-push-plugin.

Once downloaded it says that it's ready to use anywhere in my code with the ParsePushPlugin name space. When I try to use it without importing it throws the error:

Cannot find name 'ParsePushPlugin'.

Upon doing either of the following in the terminal:

cordova plugin add https://github.com/taivo/parse-push-plugin

OR

ionic plugin add https://github.com/taivo/parse-push-plugin

The result is deposited in my 'plugins' directory. This is not part of Ionic native so I can't just import from Ionic Native. I have also tried importing it from the plugins directory using the ParsePushPlugin name space both with and without curly brackets but that does not working either. Where am I going wrong?

UPDATE I updated my package.json based on an inquiry and as of this package.json along with a full re-start the app still says that cordova is not defined.

{
  "name": "ionic-hello-world",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "2.1.1",
    "@angular/compiler": "2.1.1",
    "@angular/compiler-cli": "2.1.1",
    "@angular/core": "2.1.1",
    "@angular/forms": "2.1.1",
    "@angular/http": "2.1.1",
    "@angular/platform-browser": "2.1.1",
    "@angular/platform-browser-dynamic": "2.1.1",
    "@angular/platform-server": "2.1.1",
    "@ionic/storage": "1.1.6",
    "@types/parse": "^1.2.32",
    "ionic-angular": "2.0.0-rc.3",
    "ionic-native": "2.2.3",
    "ionicons": "3.0.0",
    "rxjs": "5.0.0-beta.12",
    "underscore": "^1.8.3",
    "moment": "2.10.3",
    "sweetalert": "1.1.3",
    "zone.js": "0.6.26"
  },
  "devDependencies": {
    "@ionic/app-scripts": "0.0.45",
    "typescript": "2.0.6"
  },
  "cordovaPlugins": [
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-whitelist",
    "cordova-plugin-splashscreen",
    "cordova-plugin-statusbar",
    "ionic-plugin-keyboard",
    "cordova-plugin-facebook4",
    "cordova-plugin-nativestorage",
    "parse-push-plugin"
  ],
  "cordovaPlatforms": [
    "ios",
    {
      "platform": "ios",
      "version": "",
      "locator": "ios"
    }
  ],
  "description": "CPM: An Ionic project"
}

Upvotes: 0

Views: 407

Answers (2)

rashadb
rashadb

Reputation: 2543

To be 100% clear. In order to use the Taivo Parse Push Plugin library with Ionic2/Angular2:

1) Download the library from github. git clone https://github.com/taivo/parse-push-plugin

2) You do not import this library like you do things from ionic/native or node_module libraries. In any component that you would like to use it simply do this below your imports in the given ts file:

declare var ParsePushPlugin: any;

From here you are ready to go and ParsePushPlugin has all of the capabilities outlined in the docs.

Upvotes: 0

Suraj Rao
Suraj Rao

Reputation: 29614

set

declare var cordova:any;

and use like this:

platform.ready().then(
    () => {
        console.log("MyApp::constructor platform.ready");
        cordova.plugins.ParsePushPlugin.// settings and methods.
    }
);

Check this answer

Note: Cordova plugins do not work with ionic serve as they are not loaded to the browser. You will need to test in a phone.

Upvotes: 2

Related Questions