Android 장치로 보내기 위해 서버에서 FireBase Cloud Messaging (FCM)으로 푸시 알림을 성공적으로 전송했습니다. 하지만 FCM이 이러한 알림을 기기에 전송하지 않는 이유를 모르겠습니다.
내 코드는 다음과 같습니다.
서버 (C #)에서 FCM에 알림
public static void SendPushNotification()
{
string serverKey = "AAAA...z";
try
{
var result = "-1";
var webAddr = "https://fcm.googleapis.com/fcm/send";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("Authorization:key=" + serverKey);
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"to\": \"f..A:..p_G\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}";
streamWriter.Write(json);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
위 요청에 대한 내 응답
{ "multicast_id": 5002368547300, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "0 : 14200031 % 09c4rrr5787egg"}]}
FCM이 새 알림을 받으면 해당 알림을 각 Android 기기로 푸시한다고 가정합니다.
그러나 저에게는 작동하지 않습니다.
아래 링크를 참조하여 해결책을 얻었습니다.
성공적인 응답에도 불구하고 Firebase 푸시 알림이 전화에 표시되지 않음
위의 링크에서 언급했듯이 'json'문자열을 변경하면 작동합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다