首页 > 解决方案 > 离子:通过firebase从设备发送推送通知到设备:从iOS发送不起作用

问题描述

使用此代码从设备向设备发送推送通知可以正常工作,但仅适用于 Android 和浏览器。

出于某种原因,这在 iOS 上不起作用,无论我使用 postData 对象还是字符串化的有效负载。任何想法为什么?

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);

标签: androidiosangularfirebaseionic4

解决方案


解决这个问题的唯一方法是使用“@ionic-native/http/ngx”而不是“@angular/common/http”。仍然不明白为什么谷歌服务器拒绝接受我的有效载荷。


推荐阅读