2

我正在開發和android的離子應用程序。Ionic Push Notification不在疊加層上顯示通知(通知欄)

我實現了當應用程序運行時我收到一條警告消息是以下罰款離子文檔和this tutorial

離子推送通知。但是,當應用程序關閉時,我使用ionic.io「一次性通知」推送通知,我只聽到聲音。

推送通知會觸發我手機的默認鈴聲,但不會顯示標題或消息。

我真的很感激,如果我能在這個問題上得到任何幫助。

這裏是我的代碼:

.run(function($ionicPlatform,$httpBackend, baseURL, $rootScope, $cordovaNetwork) { 
    $ionicPlatform.ready(function() { 

     var io = Ionic.io(); 

     var push = new Ionic.Push({ 
      "onNotification": function(notification) { 
      alert('Received push notification!'); 
      console.log(notification); 
      }, 
      "pluginConfig": { 
      "android": { 
       "iconColor": "#0000FF" 
      } 
      } 
     }); 
     var user = Ionic.User.current(); 

     if (!user.id) { 
      user.id = Ionic.User.anonymousId(); 
     } 

     var callback = function(data) { 
      push.addTokenToUser(user); 
      user.save(); 
     }; 
     push.register(callback); 
     //More code... 

無控制檯錯誤,應用程序工作正常。

這裏是我的插件列表:

com.ionic.keyboard 1.0.4 "Keyboard" 
cordova-plugin-console 1.0.2 "Console" 
cordova-plugin-device 1.1.1 "Device" 
cordova-plugin-geolocation 2.1.0 "Geolocation" 
cordova-plugin-network-information 1.2.0 "Network Information" 
cordova-plugin-splashscreen 3.2.0 "Splashscreen" 
cordova-plugin-whitelist 1.2.1 "Whitelist" 
ionic-plugin-keyboard 1.0.8 "Keyboard" 
phonegap-plugin-push 1.5.3 "PushPlugin" 

和模塊:

angular-websocket 
ionic 
ionic-platform-web-client 
ionic-service-core 
ionic-service-push 
ngCordova 
platform 

這裏是我的index.html:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <meta name="format-detection" content="telephone=no"> 
    <meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; script-src &apos;self&apos; &apos;unsafe-inline&apos; &apos;unsafe-eval&apos; *; style-src &apos;self&apos; &apos;unsafe-inline&apos; *; 
    media-src *; img-src &apos;self&apos; data: *"> 
    <!-- Good default declaration: 
     * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication 
     * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly 
     * Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: 
      * Enable inline JS: add 'unsafe-inline' to default-src 
      * Enable eval(): add 'unsafe-eval' to default-src 
    --> 

    <title></title> 

    <!-- Ionic styles --> 
    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 
    <!-- Bootstrap styles --> 
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"> 
    <link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css"> 
    <link rel="stylesheet" type="text/css" href="css/style.css"> 
    <link rel="stylesheet" type="text/css" href="css/fonts/armyrust.ttf"> 

    <!-- FontAwesome Icons --> 
    <link rel="stylesheet" href="css/font-awesome.css"> 

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
    <link href="css/ionic.app.css" rel="stylesheet"> 
    --> 
    <!-- Bootstrap js --> 
    <script type="text/javascript" src="js/jquery.js"></script> 
    <script type="text/javascript" src="js/bootstrap.min.js"></script> 
    <!-- ionic/angularjs js --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 
    <script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script> 
    <script src="lib/ngCordova/dist/ng-cordova.min.js"></script> 
    <script src="lib/ionic-service-core/ionic-core.js"></script> 
    <script src="lib/ionic-service-push/ionic-push.js"></script> 
    <script src="lib/angular-resource/angular-resource.min.js"></script> 
    <script src="js/qrcode.min.js"></script> 
    <script src="js/angular-qr.js"></script> 

    <!-- cordova script (this will be a 404 during development) 
    <script src="cordova.js"></script> --> 

    <!-- your app's js 
    <script type="text/javascript" src="../www/app/app.js"></script> 
    --> 

    <script src="js/app.js"></script> 
    <script src="js/controller.js"></script> 
    <script src="js/rankingController.js"></script> 
    <script src="js/services.js"></script> 
    <script src="js/constants.js"></script> 
    <script src="lib/angular-mocks/angular-mocks.js"></script> 


    <!-- Google Maps Library --> 
    <script src="http://maps.googleapis.com/maps/api/js?sensor=true"></script> 
    <!-- Needed for Cordova/PhoneGap (will be a 404 during development) --> 
    </head> 
    <body ng-app="MaPlay" ng-controller="AppCtrl"> 
    <ion-nav-view> 

    </ion-nav-view> 
    </body> 
    <!-- Cordova is bootstrapped by ionic-platform-web-client, uncomment this if you remove ionic-platform-web-client... --> 
<!-- <script src="cordova.js"></script> --> 
</html> 
+0

您是否正在運行Android 6.0?如果是這樣,請將其添加到您的原始文章中,以便我可以回答您的問題。 – JesseMonroy650

+0

你問題解決了嗎? – JesseMonroy650

回答

1

對不起,我遲到的反應。我一直非常忙碌。謝謝@ JesseMonroy650提問。

我結束了使用PushWoosh,但是我發現我的問題來自於沒有安裝cordova-plugin-statusbar 2.1.1「StatusBar」插件。此外,我不得不使用來初始化它在我的app.js:

  if (window.StatusBar) { 
       StatusBar.styleLightContent(); 
      } 

希望這可以幫助任何人以同樣的問題,因爲運行它從未ionicPush文檔中提到。