【问题标题】:Iphone push notification issueiphone推送通知问题
【发布时间】:2010-11-05 05:45:28
【问题描述】:

我正在处理 iphone 推送通知。我可以获得我的设备令牌。我正在使用 .net 推送 json 数据。但问题是我无法收到通知。我只想知道 .net 是否必须在托管机器中推送 json 数据?

问候, 萨蒂什

【问题讨论】:

    标签: iphone notifications push


    【解决方案1】:

    我认为这与:

    Add iPhone push notification using ASP.NET server

    通读那里的链接项目。它非常全面。你实际上可以只使用那个库......它非常好。

    除非我误解了这个问题?

    【讨论】:

    • 嗨 ginamin 感谢您的回复。我正在使用来自code.google.com/p/apns-sharp 的代码,但它表示使用正确的设备令牌和 pem 文件发送成功。但问题是在我的测试 ipod touch 中没有通知它。
    • 您需要使用设备令牌来识别推送将发送到哪个设备。 .pem 文件是您的 SSL 密钥文件。所有这些都用于使用苹果推送服务器创建流。推送指南:developer.apple.com/library/ios/#documentation/…
    • 也许我不明白...您的通知格式正确,但设备没有收到推送?听起来您的设备令牌不正确。
    【解决方案2】:

    使用以下sn-p发送推送通知

     public void PendingNotification(string DeviceToken,string message)
        {
            try
            {
                int port = 2195;
                //Developer
                String hostname = "gateway.sandbox.push.apple.com";
                //Production
                //String hostname = "gateway.push.apple.com";
                String certificatePassword = "XXXXXXX";
                string certificatePath = Server.MapPath("~/cer.p12");
                TcpClient client = new TcpClient(hostname, port);
                X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), certificatePassword);
                X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
                SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
                sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, false);
                //String DeviceToken = "XXXXXXXXXXXX";
                String LoginName = "Name";
                int Counter = 1; //Badge Count;  
                String Message = message;
                String UID = "your choice UID";
                string payload = "{\"aps\":{\"alert\":\"" + Message + "\",\"badge\":" + Counter + ",\"sound\":\"default\"},\"UID\":\"" + UID + "\",\"LoginName\":\"" + LoginName + "\"}";
                MemoryStream memoryStream = new MemoryStream();
                BinaryWriter writer = new BinaryWriter(memoryStream);
                writer.Write((byte)0);
                writer.Write((byte)0);
                writer.Write((byte)32);
                writer.Write(HexStringToByteArray(DeviceToken.ToUpper()));
                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);
            }
            catch (Exception ex)
            {
                //Response.Write(ex.Message);
            }
        }
        public static byte[] HexStringToByteArray(string hex)
        {
            return Enumerable.Range(0, hex.Length)
                .Where(x => x % 2 == 0)
                .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                .ToArray();
        }
        public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            if (sslPolicyErrors == SslPolicyErrors.None)
                return true;
            Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
            return false;
        }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多