UrbanAirship è una compagnia che aiuta gli sviluppatori a creare e inviare notifiche push alle varie app sviluppate per iOS, esponendo una serie di comode API.
Recentemente ho realizzato una semplicissima classe (utilizzabile sia in applicazioni stand-alone che in progetti Asp.Net) per l’invio di notifiche push in broadcast:
Imports System Imports System.IO Imports System.Net Imports System.Text Public Class UASPush Public Shared Function Push(ByVal testo As String) Dim APIKEY As String = "[APIKEY]" Dim APISECRET As String = "[APISECRET]" Dim request As WebRequest = WebRequest.Create("https://go.urbanairship.com/api/push/broadcast/") ' Informazioni Proxy: decommentare e compilare solo se la connessione ai server di urbanairship.com avverrà tramite proxy 'Dim cr As New System.Net.NetworkCredential("[USERNAME]", "[PASSWORD]", "[DOMAIN]") 'Dim pr As New System.Net.WebProxy("[PROXY ADDRESS]", [PROXY PORT]) 'pr.Credentials = cr 'request.Proxy = pr request.Credentials = New NetworkCredential(APIKEY, APISECRET) request.Method = "POST" Dim postData As String = "{""aps"": {""badge"": 1, ""alert"": """ & testo & """}}" Dim byteArray() As Byte = Encoding.UTF8.GetBytes(postData) request.ContentType = "application/json" request.ContentLength = byteArray.Length Dim dataStream As Stream = request.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() Dim response As WebResponse = request.GetResponse() dataStream = response.GetResponseStream() Dim reader As StreamReader = New StreamReader(dataStream) Dim responseFromServer As String = reader.ReadToEnd() reader.Close() dataStream.Close() response.Close() Return responseFromServer End Function End Class