json - GCM push different payload to different device -
i push different payload differet devices @ same time. able push same payload different devices code below.
string stringregids = null; list<string> regids = new list<string>(); //add regid list stringregids = string.join("\",\"", regids.toarray());; string applicationid = "appid"; string sender_id = "senderid"; string value = "hello"; webrequest trequest; trequest = webrequest.create("https://android.googleapis.com/gcm/send"); trequest.method = "post"; trequest.contenttype = " application/json;charset=utf-8"; trequest.headers.add(string.format("authorization: key={0}", applicationid)); trequest.headers.add(string.format("sender: id={0}", sender_id)); string postdata = "{\"collapse_key\":\"score_update\",\"time_to_live\":108,\"delay_while_idle\":true,\"data\": { \"message\" : " +"\""+value+"\",\"time\": "+"\""+system.datetime.now.tostring()+"\"},\"registration_ids\":[\""+stringregids+"\"]}"; byte[] bytearray = encoding.utf8.getbytes(postdata); trequest.contentlength = bytearray.length; stream datastream = trequest.getrequeststream(); datastream.write(bytearray, 0, bytearray.length); datastream.close(); webresponse tresponse = trequest.getresponse(); datastream = tresponse.getresponsestream(); streamreader treader = new streamreader(datastream); string sresponsefromserver = treader.readtoend(); treader.close(); datastream.close(); tresponse.close();
is there solution send multiple payload multiple devices?
there no shortcut sending different payloads different devices. you'll have send each message in separate http request. each request contain single registration id.
Comments
Post a Comment