簡體   English   中英

離子:通過 firebase 從設備到設備發送推送通知:從 iOS 發送不起作用

[英]Ionic: Send Push Notifications via firebase from device to device : Sending doesn't work from 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);

解決這個問題的唯一方法是使用“@ionic-native/http/ngx”而不是“@angular/common/http”。 仍然不明白為什么谷歌服務器拒絕接受我的有效載荷。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM