ionic pushでプッシュ通知を実装する 2: full push
概要:
この後に
エラー:
解決:
実機でしかテストできない。
実機を使う(Android)
BUILD FAILED
Total time: 5.096 secs
Error: /Users/HOkaniwa/ionic_projects/bitCake-prototype/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
> Could not find any version that matches com.google.android.gms:play-services-gcm:9.0.2+.
Versions that do not match:
8.3.0
8.1.0
7.8.0
Searched in the following locations:----- ファイルリスト
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
------
問題:実機がダメなのではなくてionic build androidが出来ていない。
ionic platform add android はすでにしてある。
解決:Android Support Library and Android support Repository をインストール
Android StudioでAndroid SDK Managerを開いて、ライブラリをアップデートする - Qiita
結果:
Note: /Users/local/ionic_projects/bitCake-prototype/platforms/android/src/org/apache/cordova/splashscreen/SplashScreen.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
問題:ionic run androidをすると device not found
emulatorでしかエミュレートできない。
解決1:adb を使って携帯を認識する
adbをMacのターミナルで使えるようにする - Qiita
解決2:端末を指定してionic runする
解決3:再起動、Macに接続、Androidを開く、「OK」する
ーー
問題:実機でログを見れない
解決:adb logcat
問題:長すぎるログ
テキストファイルにする:
How to pull a Logcat file from your android device - YouTube
他の方法:
android - Get devices token? - Stack Overflow
他のチュートリアル
The following docs demonstrate the different capabilities of the Ionic.Push
service that you get with the Ionic platform web client.
How to identify if device token is for android or iOS? - Stack Overflow
➜ pushTest ionic plugin add phonegap-plugin-push --variable SENDER_ID=bitcake01
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
Plugin doesn't support this project's cordova-ios version. cordova-ios: 3.8.0, failed version requirement: >=4.1.0
Skipping 'phonegap-plugin-push' for ios
Using this version of Cordova with older version of cordova-ios is being deprecated. Consider upgrading to cordova-ios@4.0.0 or newer.
cp: no such file or directory: /Users/local/ionic_projects/pushTest/resources/ios/icon/icon-40@3x.png
Saving plugin to package.json file
=>?
ーーーー
問題:
Ionic Push: GCM_INVALID_REGISTRATION
logを見る
ionic run android -l -c -s
解決:
device token をlogから取ってくる
device token は device id (15文字の数字)ではない!
結果:curl コマンド
curl -X POST -H "Authorization: Bearer API_KEY" -H "Content-Type: application/json" -d '{
"tokens": ["DEVICE_TOKEN"],
"profile": "profile01",
"notification": {
"message": "This is my demo push!"
}
}' "https://api.ionic.io/push/notifications"