gpt4 book ai didi

android - Cordova Android 应用程序不从服务器端接收 FCM 通知

转载 作者:搜寻专家 更新时间:2023-11-01 09:39:23 24 4
gpt4 key购买 nike

我一直陷入 Cordova Android 应用程序问题,我尝试通过 Cordova 的 Firebase 插件接收 FCM 通知,每次我通过 Firebase 控制台发送通知时,设备都会收到消息,但是当我尝试使用 Firebase API 时我的服务器端,它说它已发送通知(状态 200),但设备没有收到任何通知。

即使我尝试通过 Postman 测试发送通知,同样的情况也会发生,发送状态出现 200,但设备上没有消息到达。

我的服务器端是基于 .NET 构建的。如果有人可以帮助我,我将不胜感激。

Public Function SendNotificationToFirebaseCloud() As [String]
Dim result = "-1"
Dim webAddr = "https://fcm.googleapis.com/fcm/send"

Dim httpWebRequest = DirectCast(WebRequest.Create(webAddr), HttpWebRequest)
httpWebRequest.ContentType = "application/json"
httpWebRequest.Headers.Add("Authorization:key=MY_AUTHORIZATION_KEY")
httpWebRequest.Method = "POST"

Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
Dim json As String = "{""to"" : ""MY_FIREBASE_TOKEN"", ""priority"": ""high"", ""data"" : { ""name"" : ""VIP"", ""othername"" : ""Leiloes"" }}"
streamWriter.Write(json)
streamWriter.Flush()
End Using

Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
Using streamReader = New StreamReader(httpResponse.GetResponseStream())
result = streamReader.ReadToEnd()
End Using

Return result
End Function

最佳答案

您的 JSON 中应该有一个“通知”字段,因为结构需要:

{
"to" : "xxxx",
"priority" : "high",
"notification" : {
"title" : "Your title",
"body" : "Your body",
"click_action" : "FCM_PLUGIN_ACTIVITY", //(This one is important as it's used to trigger the event when you click on the notification)
"icon" : "myicon",
"sound" : "default"
},
"data" : {
"name" : "VIP",
"othername" : "Leiloes"
}
}

关于android - Cordova Android 应用程序不从服务器端接收 FCM 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40764237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com