2016-04-12 90 views
0

我正在学习如何使用推送通知离子应用程序。我建立一个测试应用程序,我碰到下面的错误输出:离子推送通知:getPushPlugin未定义

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</<[email protected]://192.168.223.1:8100/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js:3:11085 
[33]</k</<[email protected]://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</[email protected]://192.168.223.1:8100/lib/ionic/js/ionic.bundle.js:29404:15 
ionicViewSwitcher.create/[email protected]://192.168.223.1:8100/lib/ionic/js/ionic.bundle.js:55170:15 
[email protected]://192.168.223.1:8100/lib/ionic/js/ionic.bundle.js:55134:15 
[email protected]://192.168.223.1:8100/lib/ionic/js/ionic.bundle.js:55106:15 
6  300754 error Ionic User:, [object Object] 

我假设的这个最相关的部分是第一线,说明该getPushPlugin是不确定的。另外,dev_push正在为我工​​作,但现在我正试图做真正的推送通知,这是行不通的。

我已经安装使用PhoneGap的插件:

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

这里是我的控制器代码:

.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); 
    }); 
}) 

编辑:

这是试图在真实设备上运行的结果:

$ 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 

预先感谢您。

+0

你用什么命令来建立它? ios还是android? –

+0

@Ariel我实际上并没有使用build命令。我使用'离子发球'并启用控制台日志输出 – ImStillPondering

+0

它不适用于浏览器。你必须在真实的​​设备上运行。 –

回答

0

您在真实设备上运行的错误已经解决,请查看this

第一步:对于离子推送通知,而无需使用GCM请参阅此blog

step2:对于android或ios的云端推送通知,请看看ng-cordova 推送通知和步骤。

第三步:云注册遵循Cloud-Push 和注册后,请按照How-To-Create-AndroidPushNotification