How can I use the Parse push plug-in in an Ionic 2 application?

综合技术 2018-01-01

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?

UPDATEI 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"
}

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.

Hello, buddy!

责编内容by:Hello, buddy! (源链)。感谢您的支持!

您可能感兴趣的

20170614 前端开发日报 github上的那些神器;《 JS 高程3》—— 内存回收、垃圾收集、内存泄漏;手把手带你用 Vue 撸后台(三):实战篇;前端计划—— JavaScript 中关于setTime...
Introducing Akita: A New State Management Pattern ... Akita Every developer knows state management is difficult . Con...
Effective Angular Testing Angular provides a lot of great tools for testing your application. Unfortunately, this wide arra...
angularjs结合html5的拖拽行为 闲聊: 小颖公司的项目之前要实现一个将左侧树中当前拖拽的内容,动态添加到右侧树种,虽然这个模块当时没有分给小颖,是同事完成的(小颖也不会嘻嘻),后来看了下他写代码,小颖自己写了个小demo。...
Updating to Angular’s HttpClient for Simpler... HttpClient introduces a simpler way to make HTTP calls and a whole bunch of new features. In this po...