【发布时间】:2016-06-16 13:49:48
【问题描述】:
我在使用 ionic.io 和 phonegap-plugin-push 实现推送通知时遇到问题。 这是我的开发环境::
our system information:
Cordova CLI: 6.2.0
Gulp version: CLI version 3.9.1
Gulp local:
Ionic Framework Version: 1.3.1
Ionic CLI Version: 1.7.15
Ionic App Lib Version: 0.7.2
OS: Distributor ID: LinuxMint Description: Linux Mint 17.1 Rebecca
Node Version: v0.12.2
Installed platforms:
android 5.1.1
Testing Device:
Samsung Galaxy Core Prime LTE Android 4.4.4 (rooted)
所以我按照 www dot devdactic dot com/ionic-push-notifications-guide/ 上的教程进行操作 并尝试使用插件实现推送通知
ionic add ionic-platform-web-client
ionic plugin add phonegap-plugin-push --variable SENDER_ID="1234567890"
现在我可以在我的浏览器中使用开发或演示推送通知。但是,当我尝试实现真正的推送通知并在设备上对其进行测试时,它不起作用。当应用程序启动时,它会按照教程中的预期成功生成设备令牌。但是,当我使用令牌为推送通知发送 CURL 或 Postman http 请求时,我得到一个 json 响应,就像我使用成功的 dev_push 通知(HTTP 状态 201)一样,但我从未在我的设备上收到实际的推送通知.我已经仔细检查了所有内容,例如确保 dev_push 设置为 false,我什至从头开始尝试了 3 次教程,以及 ionic 文档中的教程。在所有情况下,我都成功生成了一个开发令牌,并且我的 cURL 请求给出了肯定的响应,但设备上没有收到任何内容。
我的代码::
app.js:
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("Device token:",token.token);
push.saveToken(token); // persist the token in the Ionic Platform
});
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
index.html ---> http://pastebin.com/p9zwYXiQ
config.xml、package.json、postman 请求和响应 ---> http://pastebin.com/YT2Kn64W
【问题讨论】:
-
你遇到了什么问题
-
设备未收到通知。无论如何,我已经通过使用 One Signal 解决了这个问题。
标签: android angularjs cordova ionic-framework push-notification