Asp.net İle Onesignal Bildirim Gönderme
15 Haziran 2020 / 18:20
Burak
Merhabalar,
Asp.net ile onesignal bildirim göndermek için aşagıdaki kodlar kullanabilirsiniz. Öncelikle onesignal kendi sitesinde App ip ve Rest api key almanız lazım

Asp.net İle Onesignal Bildirim Gönderme
1.Adım Kütüphaneyi yükle
1 2 3 4 5 6 7 8 9 10 |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Net; using System.Text; using System.Web.Script.Serialization; |
2.Adım herhangi bir event ( Buton click, pageload vss )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest; request.KeepAlive = true; request.Method = "POST"; request.ContentType = "application/json; charset=utf-8"; request.Headers.Add("authorization", "Basic app key"); var serializer = new JavaScriptSerializer(); var obj = new { app_id = "app id", contents = new { en = "Test Mesajınız gelicek buraya" }, url = "bildirime tıklayınca acılacak url", included_segments = new string[] { "All" } }; var param = serializer.Serialize(obj); byte[] byteArray = Encoding.UTF8.GetBytes(param); string responseContent = null; try { using (var writer = request.GetRequestStream()) { writer.Write(byteArray, 0, byteArray.Length); } using (var response = request.GetResponse() as HttpWebResponse) { using (var reader = new StreamReader(response.GetResponseStream())) { responseContent = reader.ReadToEnd(); } } } catch (WebException ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd()); Response.Write(ex.Message); } Response.Write(responseContent); |
Bu kadar 🙂 Bir sonraki kodlamada görüşünceye kadar bol sorgulu günler
Etiketler: asp.net onesignal, asp.net onesignal push notify
Bu Yazılarıda Okuyabilirsiniz...
Bir cevap yazın