【问题标题】:Ionic: Send Push Notifications via firebase from device to device : Sending doesn't work from iOS离子:通过firebase从设备发送推送通知到设备:从iOS发送不起作用
【发布时间】:2020-02-15 00:11:17
【问题描述】:

使用此代码在设备之间发送推送通知可以正常工作,但仅适用于 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);

【问题讨论】:

    标签: android ios angular firebase ionic4


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-12-07
      • 2020-12-24
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      相关资源
      最近更新 更多