ionic pushでプッシュ通知を実装する 1:limited push
以下Limited Push Tutorialから:
エラー:ionic plugin add phonegap-plugin-push
Updated the hooks directory to have execute permissions
Fetching plugin "phonegap-plugin-push" via npm
Error: Variable(s) missing (use: --variable SENDER_ID=value).
解決:
ionic plugin add phonegap-plugin-push --variable SENDER_ID="アンドロイドアプリの「プロジェクトID」"
Updated the hooks directory to have execute permissions
Fetching plugin "phonegap-plugin-push" via npm
Installing "phonegap-plugin-push" for android
Installing "phonegap-plugin-push" for ios
Saving plugin to package.json file
参考:
cordova - Ionic Android Push Notification getting error on phonegap-plugin-push - Stack Overflow
エラー:cURLでのプッシュ通知開始時
Getting Started · Ionic.io Documentation
curl -H "Authorization: Bearer キーがここに入る" https://api.ionic.io/auth/test
{"meta": {"status": 401, "version": "2.0.0-beta.0", "request_id": "873c3328-a2ab-42a8-bb3d-26941e477385"}, "error": {"type": "Unauthorized", "link": null, "message": "JWT decode error occurred."}}%
http://docs.ionic.io/v2.0.0-beta/docs/api-getting-started#section-creating-a-token
解決策:
・app.jsのコードを正しくした
・API Keys(Legacy API)ではなくAPI Keysを作成した
=> 解決!
次にこれを打ったら:
curl -X POST -H "Authorization: Bearer API_TOKEN" -H "Content-Type: application/json" -d '{ "tokens": ["DEV_DEVICE_TOKEN"], "profile": "fake_push_profile", "notification": { "message": "Hello World!" } }' "https://api.ionic.io/push/notifications"
エラー:
{"meta": {"version": "2.0.0-beta.0", "request_id": "8^^^^^^^^^^9", "status": 422}, "error": {"message": "Invalid JSON in request body. For empty JSON, pass '{}'.", "type": "UnprocessableEntity", "link": null}}%
解決策
・Ionic DashboardでのAPI Keys詳細設定(Apple, Android連携)をしていないこと
・Androidアプリの設定をしていないこと
Android Push Profiles · Ionic.io Documentation
・JSONの表記がおかしかった
スクリプトファイル(~~.sh)を作って、そこにコマンドを打つ。
改行ができる。
例:
➜ vi script.sh
ファイル編集 (ここからLimited Setup · Ionic.io Documentation)
➜ chmod +x script.sh
➜ ./script.sh
{"meta": {"request_id": "-----", "status": 201, "version": "2.0.0-beta.0"}, "data": {"config": {"profile": "limitedpushprofile01", "tokens": ["DEV------------"], "notification": {"message": "Hello!"}}, "app_id": "ee60ffrrff", "uuid": "sfrgrdg-e40b-4rrgr-rfef08-----------", "status": "open", "created": "2016-08-08T02:36:31.086718+00:00", "state": "enqueued"}}%
使えるかも:JSONLint - The JSON Validator.
他のチュートリアル
The Complete Ionic Push Notifications Guide
cordova + ionicでプッシュ通知(iOS)の1から9! - 鈴木商店ブログ
https://www.airpair.com/ionic-framework/posts/push-notifications-using-ionic-framework
Push Notifications in Ionic Apps with Google Cloud Messaging
他
AIzaSyAqAIcbBP9TzhlrKUgQzBIh97ODHFZsWl3Y