Sending push notifications from device to device works fine with this code, but only on Android and from a browser.
For some reason this does not work on iOS, no matter if I use the postData object or the stringified payload. Any ideas why?
import { HttpClient } from '@angular/common/http';
public sendPushNotificationToToken(token: string, pnServerKey: string, message: string, userId: number): Observable<any> {
const firebaseUrl = "https://fcm.googleapis.com/fcm/send";
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'key=' + pnServerKey
})
};
const postData = {
'to': token,
'priority':'normal',
'notification': {
'title': message,
'message': message,
'userId': userId
},
};
return this.http.post(firebaseUrl, postData, httpOptions);
The only way to solve this was to use "@ionic-native/http/ngx" instead of '@angular/common/http'. Still don't see why the google Server refused to accept my payload.