簡體   English   中英

離子推送通知不在疊加層上顯示通知(通知欄)

[英]Ionic Push Notification not displaying notifications on overlay (Notification bar)

我正在為Android開發和離子應用程序。

我在離子文檔和本教程之后實現了Ionic推送通知

當應用程序運行時,我收到一條警告消息,這很好。 但是,當應用程序關閉並且我使用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>

回復晚了非常抱歉。 我一直很忙。 謝謝@ JesseMonroy650。

我最終使用了PushWoosh,但是我發現我的問題來自於沒有安裝cordova-plugin-statusbar 2.1.1“StatusBar”插件。 我還必須使用以下命令在app.js中初始化它:

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

希望這可以幫助任何運行相同問題的人,因為它在ionicPush文檔中從未提及過。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM