3

If I send notification to iOS device from FCM console I am getting the message alert on notification center (swipe down from the Top of the screen to view Notification Centre).

didRecievedRemoteNotification Output is :

{

    aps =     {

        alert = "From console";

    };

    "gcm.message_id" = "0:1470206236110595%b2c76869b2c76869";

    "gcm.n.e" = 1;

    "google.c.a.c_id" = 2979094970349938289;

    "google.c.a.e" = 1;

    "google.c.a.ts" = 1470206236;

    "google.c.a.udt" = 0;

}

But if send notification to iOS device I am sending using api from my server I am not receiving message alert on notification center (swipe down from the Top of the screen to view Notification Centre).

didRecievedRemoteNotification Output is :

{

    "collapse_key" = "do_not_collapse";

    from = 67981113117;

    message = "alert from api";

    time = "03-08-2016 12:44:53";

}

My API code is which is in C#:

string RegIDs = "some id";





                var appID = "some id";


                var SenderID = "some id";
                var value = Text1.Text;
                WebRequest tRequest;



            tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");

                tRequest.Method = "POST";
                tRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                tRequest.Headers.Add(string.Format("Authorization: key={0}", appID));

                tRequest.Headers.Add(string.Format("Sender: id={0}", SenderID));


                //Data_Post Format
                // string postData = "{'collapse_key' : 'demo', 'registration_id': [ '" + regId + "' ], 
                //'data': {'message': '" + Label1.Text + "'},'time_to_live' : '3' }";

            //json for android 
                string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message="
                   + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + RegIDs + "";



            Console.WriteLine(postData);
                Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                tRequest.ContentLength = byteArray.Length;

                Stream dataStream = tRequest.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();

                WebResponse tResponse = (WebResponse)tRequest.GetResponse();


                dataStream = tResponse.GetResponseStream();

                StreamReader tReader = new StreamReader(dataStream);

                String sResponseFromServer = tReader.ReadToEnd();

                Label3.Text = sResponseFromServer; //printing response from GCM server.
                tReader.Close();
                dataStream.Close();
                tResponse.Close();
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mohammed Ebrahim
  • 849
  • 1
  • 12
  • 22
  • Try and verify if you are formatting the downstream message correctly, check [sending downstream messages from the server](https://firebase.google.com/docs/cloud-messaging/downstream).You may have coded the wrong or not supported format. Remove the `timetolive` as it is not yet is not supported for notification messages on [iOS](https://developers.google.com/cloud-messaging/concept-options). – Mr.Rebot Aug 05 '16 at 06:54
  • http://stackoverflow.com/questions/38479668/firebase-api-is-not-sending-push-notifications-when-using-the-api/ – Kishore Relangi Oct 24 '16 at 05:34

1 Answers1

0

Another alternative in order to test push notifications without using Firebase console is using Postman. Attached two images with configuration details.

Image 1: Set notification payload enter image description here

Image 2: Set request headers ( Content-Type and Authorization ) enter image description here

Firebase push notification endpoint: https://fcm.googleapis.com/fcm/send

Joule87
  • 532
  • 4
  • 13