我正在为Android开发和离子应用程序。
我已经在离子文档和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 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *;
media-src *; img-src 'self' 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 :(得分:1)
对于迟到的回复感到抱歉。我非常忙碌。谢谢@ JesseMonroy650的询问。
我最终使用了PushWoosh,但是我发现我的问题来自没有cordova-plugin-statusbar 2.1.1&#34; StatusBar&#34;安装插件。我还必须使用以下命令在我的app.js中初始化它:
if (window.StatusBar) {
StatusBar.styleLightContent();
}
希望这可以帮助任何运行同一问题的人,因为它在ionicPush文档中从未提及。