Ionic 3- I am using this plugin “https://github.com/phonegap/phonegap-plugin-push” for push notifications with firebase.
When the app is closed push notifications coming for the android phone but not for iOS. When we open app on the iOS phone then notifications coming.
https://firebase.google.com/docs/cloud-messaging/http-server-ref
I am using below code for sending push notifications:
function send_notification_to_user_mobile($title, $message, $userId, $notificationType, $dataId) {
$DEVICE_TOKEN = get_user_meta($userId,‘firebase_device_token’,TRUE);
$current_user_id = getUserId();
$display_name = bp_core_get_user_displayname($current_user_id);
$message = ‘’.$display_name.’’.$message;
if(!empty($DEVICE_TOKEN)){
$SERVER_KEY = ‘adfsdadfsdsafsdafdsasdsafdasd’;
$data =
array(
‘data’=> array(
‘title’=> $title,
‘message’=> $message,
‘isadmin’=> ‘no’,
‘notificationType’=> $notificationType,
‘dataId’=> $dataId,
),
‘content_available’=> true,
‘priority’=> ‘high’,
‘to’=> $DEVICE_TOKEN,
);
$data_json = json_encode($data);
$request_headers = array();
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Authorization: key='.$SERVER_KEY;
$ch = curl_init();
$url = 'https://fcm.googleapis.com/fcm/send';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
}
}