2016-11-23 72 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之前一切正常,但是消息不會被傳遞。 –

相關問題