我正在敲打着我的头,因为我无法找到为什么我的推送通知不起作用。
小版本列表:
$ cordova plugin info
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-splashscreen 4.0.1 "Splashscreen"
cordova-plugin-statusbar 2.2.1 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-push 1.8.4 "PushPlugin"
$ ionic info
Cordova CLI: 6.5.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v5.12.0
Xcode version: Not installed
以下是为推送系统注册的代码:
// In config
$ionicCloudProvider.init({
core: {
app_id: "xxxx"
},
push: {
sender_id: "yyyyyy",
pluginConfig: {
ios: {
badge: true,
},
android: {
iconColor: "#343434"
}
}
}
});
// In controller
// Register Push notifications
$ionicPush.register().then(function (t) {
console.log('register successfull', t);
return $ionicPush.saveToken(t, {
ignore_user: true
});
}).then(function (t) {
console.log('Token saved:', t);
alert('Token saved:', t.token);
});
我正在使用USB安卓手机进行调试,其中包含:
ionic run android
然后我检查镀铬设备检查员,看看发生了什么。 事情是,“注册成功”'出现了,"正确"令牌
{
"token": "fWjLt4mOttw:APA91bE4KCycHlu92T6fJTzMFbRFtJdTUrb2u9jv5LTO2yTPD_-sKshbqo93UStwjdJpmLun2tJBCgegaUYnlj9kxxFWFPi9hobZH5W80OnrsPdfxrdYNmp8SYM_SXp-5RiknFrbPl5l",
"app_id": "XXXXXX"
}
但saveToken方法因404错误而失败。当我在我的shell中使用curl重播请求时(右键单击>复制>作为curl),我没有错误......这是chrome控制台日志:
POST https://api.ionic.io/push/tokens 404 (Not Found)
Ionic Push: Error: Not Found
at q.<anonymous> (app.js:formatted:717)
at q.t.emit (app.js:formatted:9164)
at XMLHttpRequest.n.onreadystatechange (app.js:formatted:9424)
这是curl的输出(似乎正确)
{
"meta": {
"status": 201,
"version": "2.0.0-beta.0",
"request_id": "92487e15-9f2a-416f-c15b-9129e9e10049"
},
"data": {
"token": "fWjLt4mOttw:APA91bE4KCycHlu92T6fJTzMFbRFtJdTUrb2u9jv5LTO2yTPD_-sKshbqo93UStwjdJpmLun2tJBCgegaUYnlj9kxxFWFPi9hobZH5W80OnrsPdfxrdYNmp8SYM_SXp-5RiknFrbPl5l",
"type": "android",
"invalidated": null,
"valid": true,
"created": "2017-03-07T16:43:58.993190+00:00",
"app_id": "f2de99a1",
"id": "c85e1bdbb6b3cf2da8f090ba59df6892"
}
}
有人能帮帮我吗? 谢谢!
答案 0 :(得分:0)
我解决了这个问题:我必须修改
<allow origin>
config.xml部分的。 404错误实际上是403,但是浏览器报告为404。