Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70435

Sending Push Notif (FCM) via Ionic Native HTTP doesn't work VS Angular HTTP

$
0
0

@Ionize wrote:

Hello, I am using the following code to send Push Notifications to devices using Google Cloud Messaging using Angular HTTP. It works when on dev build, but doesn’t work on prod build (I assume due to CORS issues). Upon searching Google, people say to use Ionic Native HTTP which upon testing worked even on prod except it’s not sending the Push Notifications despite having a post response of Status 200: Ok.

Angular HTTP

let postParams = {
   notification: {
   title: "Push Notification",
   body: "This is a sample push notification",
   sound: "default",
   click_action: "FCM_PLUGIN_ACTIVITY",
   icon: "fcm_push_icon"
},
   to: pushToken,
   priority: "high",
   restricted_package_name: ""
};

let headers = new HttpHeaders({ "Content-Type": "application/json", Authorization: "key=" + gcmKey });
let options = { headers: headers };

this.http.post("https://fcm.googleapis.com/fcm/send", postParams, options).subscribe(response => {
   //Response with multicast ID.
   resolve(response);
}, err => {
   reject(err);
});

Ionic Native HTTP

let body = {
   notification: {
      title: "Push Notification",
      body: "This is a sample push notification",
      sound: "default",
      click_action: "FCM_PLUGIN_ACTIVITY",
      icon: "fcm_push_icon"
   },
   to: pushToken,
   priority: "high",
   restricted_package_name: ""
};

let headers = { Authorization: "key=" + gcmKey };
      
this.http.post("https://fcm.googleapis.com/fcm/send", body, headers).then(response => {
   //Response with 200 OK status, but no multicast ID.
   resolve(response);
}).catch(err => {
   reject(err);
});

Pretty much the same code, am I doing something wrong in my POST request? Thanks so much

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70435

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>