この質問は何度も尋ねられていますが、解決策は何も私のために働いていません。ユーザーがプッシュ通知をタップしたときにイオンアプリで特定のビューを開く
私はプッシュ通知を実装するためにionic.ioのドキュメントhttps://docs.ionic.io/services/push/に従っており、アプリケーションがフォアグラウンドにあるときにうまく動作します。アプリが閉鎖されたときにも通知を受け取ることができます。ユーザーがその通知をクリックすると、特定のビューを開きたいと思います。
ドキュメントごとに、アプリでプッシュ通知を処理するには、angleの$ onを使用してクラウド:push:通知イベントをリッスンする必要があります。
$scope.$on('cloud:push:notification', function(event, data) {
var msg = data.message;
alert(msg.title + ': ' + msg.text);
});
このコードは、アプリケーションがフォアグラウンドのときに問題なく動作します。しかし、アプリケーションが閉じられ、ユーザーがプッシュ通知をタップしてアプリを開くと、特定のビュー/コントローラを開きたいと思います。 私は上記のコードを.run関数とoutside $ ionicPlatform.ready関数に置きました。誰もがこれを達成するために私を助けることができる。ここ は
function sendFCMNotification($request_data){
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
//The device token.
$token = $request_data['device_id'];
//Title of the Notification.
$title = $request_data['title'];
//Body of the Notification.
$body = $request_data['body'];
//Creating the notification array.
$notification = array('title' =>$title , 'body' => $body,'content-available'=> '1');
//This array contains, the token and the notification. The 'to' attribute stores the token.
$arrayToSend = array('to' => $token, 'notification' => $notification);
//Generating JSON encoded string form the above array.
$json = json_encode($arrayToSend);
//Setup headers:
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key= {MY GCM KEY}';
//Setup curl, add headers and post parameters.
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
//Send the request
curl_exec($ch);
//Close request
curl_close($ch);
}
FCM RESTサービスを呼び出すために私のコードですか?
Pushwooshは、プッシュ通知をクリックしてアプリを起動したかどうかを教えてくれます。 https://rawgit.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin/master/Documentation/files/PushNotification-js.html#PushNotification.getLaunchNotification
イオンプッシュプラグインに類似の機能はありますか?
こんにちは、私は直接FCMのREST APIを呼び出しています。私はそれを試してみてください。 –
それが動作するかどうか教えてください@NeelKamal –
ありがとうございます。それは働いている。しかし、FCMに直接送ったときになぜそれがうまくいかなかったのか分かりません。ペイロードを追加すると動作します。必ずそれを試してみましょう。回答が役に立った場合は –