How do I send API push message with .Net / Parse.com? (C#)

后端 未结 2 1346
既然无缘
既然无缘 2020-12-17 07:18

This is my application code for sending push message using PARSE

public static string ParseAuthenticate(string strUserName, string 
{
var httpWebRequest = (H         


        
相关标签:
2条回答
  • 2020-12-17 07:37

    Bellow code is running for push notification using parse in .net.

    private bool PushNotification(string pushMessage)
    {
        bool isPushMessageSend = false;
    
        string postString = "";
        string urlpath = "https://api.parse.com/1/push";
        var httpWebRequest = (HttpWebRequest)WebRequest.Create(urlpath);
        postString = "{ \"channels\": [ \"Trials\"  ], " +
                         "\"data\" : {\"alert\":\"" + pushMessage + "\"}" +
                         "}";
        httpWebRequest.ContentType = "application/json";
        httpWebRequest.ContentLength = postString.Length;
        httpWebRequest.Headers.Add("X-Parse-Application-Id", "My Parse App Id");
        httpWebRequest.Headers.Add("X-Parse-REST-API-KEY", "My Rest API Key");
        httpWebRequest.Method = "POST";
        StreamWriter requestWriter = new StreamWriter(httpWebRequest.GetRequestStream());
        requestWriter.Write(postString);
        requestWriter.Close();
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            var responseText = streamReader.ReadToEnd();
            JObject jObjRes = JObject.Parse(responseText);
            if (Convert.ToString(jObjRes).IndexOf("true") != -1)
            {
                isPushMessageSend = true;
            }
        }
    
        return isPushMessageSend;
    }
    
    0 讨论(0)
  • 2020-12-17 07:40

    To send Notification to all app user you have to set the Data field like so:

    postString = "{\"data\": { \"alert\": \"Test Notification 2 From Parse Via Chinwag Admin\" },\"where\": { \"deviceType\": \"ios\" }}";
    
    0 讨论(0)
提交回复
热议问题