2016-11-23 75 views
1

我一直被困在Cordova Android应用程序问题中,我试图通过Firebase插件接收FCM通知,每当我通过Firebase控制台发送通知时,设备会收到消息,但是当我尝试在服务器端使用Firebase API时,它说它发送的通知(状态200),但设备不会收到任何通知。Cordova Android应用程序不会收到来自服务器端的FCM通知

即使当我尝试测试邮差发送通知时,也会发生同样的情况,发送发送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 

回答

2

你应该有一个“通知”字段的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" 
    } 
} 
+0

我试试你的解决方案@NicolasAlric,但仍是同样的情况。 –

+0

尝试添加 '“title”:“您的标题”, “body”:“您的身体” 到您的数据字段 –

+0

仍然没有在al。我认为json格式是正确的,但是,从Firebase将消息发送到设备时会出现问题。帖子请求的状态是200,在firebase之前一切正常,但是消息不会被传递。 –

相关问题