c# - How to send a notification to a specific device using PARSE REST API with ASP.NET? -
can send push-message within app 1 specific device (probably device token ?) instead of sending devices ?
here code
public static bool pushnotification(string pushmessage) { bool ispushmessagesend = false; string poststring = ""; string urlpath = "https://api.parse.com/1/push"; var httpwebrequest = (httpwebrequest)webrequest.create(urlpath); poststring = "{ \"devicetype\": \"ios\"," + "\"devicetoken\": \"xxxxxxxxxxx\"," + "\"channels\": [\"\"], " + "\"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; }
according documentation, can send notifications queries. , queries can specific device given id.
code below curl equivalent:
curl -x post \ -h "x-parse-application-id: app_id" \ -h "x-parse-rest-api-key: api_key" \ -h "content-type: application/json" \ -d '{ "where": { "installationid": "ca100000-ec00-0000-0000-000000000000" }, "data": { "alert": "special delivery! you!" } }' \
i tried real credentials, , worked. hope can implement c# version of it.
Comments
Post a Comment