1

我要疯了已经, 我试图与phonegap-plugin-push这样的工作:离子-1和PhoneGap的-插件推我让“PushNotification没有定义”

   var options = { 
        android: { 
         senderID: "****" 
        }, 
        ios: { 
         alert: "true", 
         badge: "true", 
         sound: "true" 
        }, 
        windows: {} 
       }; 

       // initialize 
       $cordovaPushV5.initialize(options).then(function (data) { 
        alert(data); 
        console.log(data); 
        // start listening for new notifications 
        $cordovaPushV5.onNotification(); 
        // start listening for errors 
        $cordovaPushV5.onError(); 

        // register to get registrationId 
        $cordovaPushV5.register().then(function (registrationId) { 
         alert(registrationId); 
         console.log(registrationId); 
         $localStorage.token = registrationId; 
        }) 
       }); 

,我得到错误:

Uncaught ReferenceError: PushNotification is not defined 
    at Object.initialize (ng-cordova.js:6378) 
    at app.js:69 

与“远程设备”我甚至不看phonegap-plugin-push enter image description here

我试图改变和WO与cordova-plugin-firebase rk,但我不gat令牌, 我试图与window.FirebasePlugin.onTokenRefreshwindow.FirebasePlugin.getToken 工作我真的尝试了一切,但没有为我工作。

我的插件:

cordova-inappbrowser 1.0.6 "InAppBrowser" 
cordova-plugin-camera 2.4.1 "Camera" 
cordova-plugin-compat 1.1.0 "Compat" 
cordova-plugin-console 1.0.5 "Console" 
cordova-plugin-device 1.1.4 "Device" 
cordova-plugin-file 4.3.3 "File" 
cordova-plugin-file-transfer 1.6.3 "File Transfer" 
cordova-plugin-firebase 0.1.24 "Google Firebase Plugin" 
cordova-plugin-geolocation 2.4.3 "Geolocation" 
cordova-plugin-splashscreen 4.0.3 "Splashscreen" 
cordova-plugin-statusbar 2.2.1 "StatusBar" 
cordova-plugin-whitelist 1.3.2 "Whitelist" 
ionic-plugin-keyboard 2.2.1 "Keyboard" 
phonegap-plugin-push 2.0.0 "PushPlugin" 

离子信息:

cli packages: (/usr/local/lib/node_modules) 

    @ionic/cli-utils : 1.9.2 
    ionic (Ionic CLI) : 3.9.2 

global packages: 

    Cordova CLI : 7.0.1 
    Gulp CLI : CLI version 3.9.1 Local version 3.9.1 

local packages: 

    Cordova Platforms : android 6.2.3 ios 4.4.0 
    Ionic Framework : ionic1 1.3.3 

System: 

    ios-sim : 6.0.0 
    Node : v6.10.2 
    npm  : 5.3.0 
    OS  : macOS Sierra 
    Xcode : Xcode 8.3.3 Build version 8E3004b 

我建立与ionic package build android 任何应用程序对我有一个解决方案吗?请!

+0

你可以试试这个链接https://stackoverflow.com/questions/38345799/pushnotification-is-undefined-ng-cordova –

+0

@sunielkalwani我尝试这一点,你可以在图片插件未装载看甚至,顺便说一句,它的工作PhoneGet的建设,但我与离子的工作,因为PhoneGap我无法取代图标和飞溅 –

回答

1

请在真实移动设备上进行测试。插件不会在浏览器中加载。

尝试在platform.ready事件之后调用initialize方法。

angular.module('MainCtrl', ['ionic']) 
.controller('PushCtrl', function($scope,$cordovaPushV5) { 

    ionic.Platform.ready(function(){ 
    // will execute when device is ready, or immediately if the device is already ready. 
    console.log('Platform ready!'); 

    // initialize 
    $cordovaPushV5.initialize(options).then(function() { 
    // start listening for new notifications 
    $cordovaPushV5.onNotification(); 
    // start listening for errors 
    cordovaPushV5.onError(); 

    // register to get registrationId 
    $cordovaPushV5.register().then(function(registrationId) { 
     // save `registrationId` somewhere; 
     console.log(registrationId); 
    }) 
    }); 
    }); 

    if(ionic.Platform.device()){ 
     console.log("Push plugin loaded"); 
    }else{ 
    console.log("App is running in browser, push plugin will not load"); 
    }  
}); 
+0

谢谢,但奇怪的是,我用'离子包构建android'构建应用程序,我下载从我的帐户(在:https://apps.ionic.io/apps)的应用程序,我得到了“应用程序在浏览器中运行,推送插件将无法加载”,我做错了什么? –

+0

你是如何运行应用程序?我的意思是你做什么程序来运行应用程序? –

+0

我下载apk安装... –