Comment préparer le backend en utilisant C # .net pour Push Notifcation sur iPhone

using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.IO; using System.Text; using System.Security.Authentication; using System.Net.Security; using System.Net.Sockets; using System.Security.Cryptography.X509Certificates; using Newtonsoft.Json.Linq; namespace WebApplication1 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnPush_Click(object sender, EventArgs e) { pushMessage(txtDeviceID.Text.Trim(), txtPayload.Text.Trim()); } public void pushMessage(ssortingng deviceID, ssortingng Mesaj) { int port = 2195; Ssortingng hostname = "gateway.push.apple.com"; Ssortingng certificateePath = HttpContext.Current.Server.MapPath("new_dev_cert.p12"); X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificateePath), "taxmann"); X509Certificate2Collection certificateesCollection = new X509Certificate2Collection(clientCertificate); TcpClient client = new TcpClient(hostname, port); SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null); try { sslStream.AuthenticateAsClient(hostname, certificateesCollection, SslProtocols.Ssl3, false); MemoryStream memoryStream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(memoryStream); writer.Write((byte)0); //The command writer.Write((byte)0); //The first byte of the deviceId length (big-endian first byte) writer.Write((byte)32); //The deviceId length (big-endian second byte) writer.Write(HexSsortingngToByteArray(deviceID.ToUpper())); Ssortingng payload = "{\"aps\":{\"alert\":\"" + Mesaj + "\",\"badge\":1,\"sound\":\"default\"}}"; writer.Write((byte)0); writer.Write((byte)payload.Length); byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload); writer.Write(b1); writer.Flush(); byte[] array = memoryStream.ToArray(); sslStream.Write(array); sslStream.Flush(); client.Close(); lblResponse.Text = "Sucess.."; } catch (System.Security.Authentication.AuthenticationException ex) { client.Close(); lblResponse.Text = ex.Message; } catch (Exception e) { client.Close(); lblResponse.Text = e.Message; } } // The following method is invoked by the RemoteCertificateValidationDelegate. public static bool ValidateServerCertificate(object sender, X509Certificate certificatee, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true; else // Do not allow this client to communicate with unauthenticated servers. return false; } private static byte[] HexSsortingngToByteArray(Ssortingng DeviceID) { //convert Devide token to HEX value. byte[] deviceToken = new byte[DeviceID.Length / 2]; for (int i = 0; i < deviceToken.Length; i++) deviceToken[i] = byte.Parse(DeviceID.Subssortingng(i * 2, 2), System.Globalization.NumberStyles.HexNumber); return deviceToken; } } } 

Ci-dessus est mon code source de l'arrière-plan pour l'envoi de notification. Mon code débogue avec succès et reçoit un message. Mais je ne suis pas en mesure d'get une notification sur iPhone.

J'ai suivi ce http://blog.serverdensity.com/how-to-build-an-apple-push-notification-provider-server-tutorial/ . Je ne sais pas où est le problème. Pouvez-vous s'il vous plaît m'aider sur cette question.

    Parcourez ce tutoriel, il explique tout ce dont vous avez besoin du début à la fin et fonctionne parfaitement. Il explique comment configurer tout le côté server et sur le périphérique ios, ainsi que sortinger tous les certificates dans le portail des développeurs.

    http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

    J'espère que cela t'aides

    Sam

     { "aps": { "alert": { "body": "Hello, world!" }, "badge": 2 } }