android - 离子:通过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);
解决方案
解决这个问题的唯一方法是使用“@ionic-native/http/ngx”而不是“@angular/common/http”。仍然不明白为什么谷歌服务器拒绝接受我的有效载荷。
推荐阅读
- django - 在 Django modelformset_factory 中传递模型实例的 id
- python - 为什么python默认启用断言
- oracle - 在 oracle sql 中从子节点中查找根父节点
- mysql - Sql:加入2个没有公共字段的表
- javascript - 以角度单击按钮后未触发 ngOnDestroy
- sails.js - 尝试在模型上实施关系后,Sails Lift 停止工作
- mysql - 如何从 Python 3 将值插入 Mysql 表中的 DATE 列
- javascript - xml中的自闭标签空间问题 - Cheerio
- nginx - Nginx 与 openssl 构建错误 CentOS 7 -“基本名称:缺少操作数”
- c++ - 为什么在向量包围的向量上使用 .pushback 时出现重叠错误