Ionic Push Notifications: getPushPlugin is undefined

孤街醉人 提交于 2019-12-12 01:54:36

问题


I am trying learn how to use push notifications for Ionic apps. I'm building a test app and I get the following error output:

Error: t._getPushPlugin(...) is undefined
[33]</k</<.value/<@http://192.168.223.1:8100/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js:3:6764
[33]</k</<.value@http://192.168.223.1:8100/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js:3:11085
[33]</k</<.value@http://192.168.223.1:8100/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js:3:6570
@http://192.168.223.1:8100/js/controllers.js:24:5
$RootScopeProvider/this.$get</Scope.prototype.$emit@http://192.168.223.1:8100/lib/ionic/js/ionic.bundle.js:29404:15
ionicViewSwitcher.create/switcher.emit@http://192.168.223.1:8100/lib/ionic/js/ionic.bundle.js:55170:15
transitionComplete@http://192.168.223.1:8100/lib/ionic/js/ionic.bundle.js:55134:15
onReflow@http://192.168.223.1:8100/lib/ionic/js/ionic.bundle.js:55106:15
6     300754   error    Ionic User:, [object Object]

I'm assuming the most relevent part of this is the first line, stating that the getPushPlugin is undefined. Also, dev_push was working for me, but now that I am attempting to do real push notifications this is not working.

I have installed the phonegap plugin using:

$ ionic plugin add phonegap-plugin-push --variable SENDER_ID="my_sender_id"

Here is my controller code:

.controller('DashCtrl', function($scope) {
  $scope.$on('$ionicView.enter', function(e) {
    console.log("if");
    var push = new Ionic.Push({
      "onNotification": function(notification) {
          console.log("Got dat notification");
      }
    });
    var io = Ionic.io();
    var user = Ionic.User.current();

    if(!user.id) {
      user.id = '1234';
    }
    user.save();

    var callback = function () {
        push.addTokenToUser(user);
        user.save();
    };

    push.register(callback);
  });
})

EDIT:

Here is the result of trying to run on a real device:

$ ionic run android
Running command: "C:\Program Files\nodejs\node.exe" C:\Users\antho\Desktop\pleasePush\hooks\after_prepare\010_add_platform_class.js C:/Users/antho/Desktop/pleasePush
add to body class: platform-android
Running command: cmd "/s /c "C:\Users\antho\Desktop\pleasePush\platforms\android\cordova\run.bat""
ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
JAVA_HOME=C:\Program Files (x86)\java\jdk1.7.0_55
WARNING : No target specified, deploying to device '2b0a9bf2'.
Running: C:\Users\antho\Desktop\pleasePush\platforms\android\gradlew cdvBuildDebug -b C:\Users\antho\Desktop\pleasePush\platforms\android\build.gradle -PcdvBuildArch=arm -Dorg.gradle.daemon=true

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
   > Could not find any version that matches com.google.android.gms:play-services-gcm:+.
     Searched in the following locations:
         https://repo1.maven.org/maven2/com/google/android/gms/play-services-gcm/maven-metadata.xml
         https://repo1.maven.org/maven2/com/google/android/gms/play-services-gcm/
         file:/C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/google/android/gms/play-services-gcm/maven-metadata.xml
         file:/C:/Program Files (x86)/Android/android-sdk/extras/android/m2repository/com/google/android/gms/play-services-gcm/
     Required by:
         :android:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4.882 secs

C:\Users\antho\Desktop\pleasePush\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                    ^
Error code 1 for command: cmd with args: /s /c "C:\Users\antho\Desktop\pleasePush\platforms\android\gradlew cdvBuildDebug -b C:\Users\antho\Desktop\pleasePush\platforms\android\build.gradle -PcdvBuildArch=arm -Dorg.gradle.daemon=true"
ERROR running one or more of the platforms: Error: cmd: Command failed with exit code 1
You may not have the required environment or OS to run this project

Thank you in advance.


回答1:


The error You get on running in your real device is already answered please look this.

step1 : For ionic push notification without using GCM please refer this blog .

step2 : For Cloud push notification for android or ios please look ng-cordova push notification and the steps.

step3 : For cloud registration follow Cloud-Push and after registering please follow How-To-Create-AndroidPushNotification.



来源:https://stackoverflow.com/questions/36564183/ionic-push-notifications-getpushplugin-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!