我正在尝试使用JavaScript客户端通过FCM
POST将HTTP
消息发送到快速应用程序。该应用程序正在接收消息,但未显示任何通知,但是当我从通知编辑器发送消息时,该通知会出现在应用程序上。请找到javascript代码。我尝试了前台和后台通知在两种情况下都不会出现。
当我从javascript发送消息时,将调用以下委托:-
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
JavaScript代码:-
function callAPI(token, i, tokenArrayLength){
var data = JSON.stringify({
"to": token,
"content_available": true,
"data": {
"message": Desc.value + "\nClick To know more about the event",
"title": Title.value
}
});
var xhr = new XMLHttpRequest();
//xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
if(i == tokenArrayLength-1){
//window.location.reload();
}
}
});
xhr.open("POST", "https://fcm.googleapis.com/fcm/send");
xhr.setRequestHeader("authorization", "key=AIzaSyDzbJ********");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
//xhr.setRequestHeader("postman-token", "668*******");
xhr.send(data);
}