苹果推送通知反馈服务不起作用

发布于 2024-10-11 05:50:51 字数 5108 浏览 3 评论 0原文

我正在开发一个使用 Apple 推送通知的 iPhone 应用程序。在 iPhone 端一切都很好,在服务器端我遇到了问题。通知发送正确,但是当我尝试查询反馈服务以获取已卸载应用程序的设备列表时,我总是得到零结果。我知道我应该获得一个结果,因为该应用程序已从我的一台测试设备上卸载。 24 小时或更长时间后,我仍然没有收到反馈服务的结果。

有什么想法吗?有谁知道反馈服务需要多长时间才能识别出我的应用程序已从我的测试设备上卸载?

注意:我的设备上还有另一个推送通知应用程序,因此我知道我的应用程序不是唯一的应用程序。

代码 - C#:

    public static string CheckFeedbackService(string certaName, string hostName)
    {
        SYLogger.Log("Check Feedback Service Started");
        ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
         // Create a TCP socket connection to the Apple server on port 2196
        TcpClient tcpClientF = null;
        SslStream sslStreamF = null;
        string result = string.Empty;
         //Contect to APNS& Add the Apple cert to our collection
        X509Certificate2Collection certs = new X509Certificate2Collection { GetServerCert(certaName) };
        //Set up
        byte[] buffer = new byte[38];
        int recd = 0;
        DateTime minTimestamp = DateTime.Now.AddYears(-1);
        // Create a TCP socket connection to the Apple server on port 2196
        try
        {
            using (tcpClientF = new TcpClient(hostName, 2196))
            {
                SYLogger.Log("Client Connected  ::" + tcpClientF.Connected);
                // Create a new SSL stream over the connection
                sslStreamF = new SslStream(tcpClientF.GetStream(), true,ValidateServerCertificate);
                // Authenticate using the Apple cert
                sslStreamF.AuthenticateAsClient(hostName, certs, SslProtocols.Default, false);
                SYLogger.Log("Stream Readable ::" + sslStreamF.CanRead);
                SYLogger.Log("Host Name ::"+hostName);
                SYLogger.Log("Cert Name ::" + certs[0].FriendlyName);

                if (sslStreamF != null)
                {
                    SYLogger.Log("Connection Started");

                            //Get the first feedback
                            recd = sslStreamF.Read(buffer, 0, buffer.Length);
                            SYLogger.Log("Buffer length ::" + recd);
                            //Continue while we have results and are not disposing
                            while (recd > 0)
                            {

                                        SYLogger.Log("Reading Started");
                                            //Get our seconds since 1970 ?
                                            byte[] bSeconds = new byte[4];
                                            byte[] bDeviceToken = new byte[32];
                                            Array.Copy(buffer, 0, bSeconds, 0, 4);
                                            //Check endianness
                                            if (BitConverter.IsLittleEndian)
                                                    Array.Reverse(bSeconds);
                                            int tSeconds = BitConverter.ToInt32(bSeconds, 0);
                                            //Add seconds since 1970 to that date, in UTC and then get it locally
                                            var Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tSeconds).ToLocalTime();
                                            //Now copy out the device token
                                            Array.Copy(buffer, 6, bDeviceToken, 0, 32);
                                            string deviceToken = BitConverter.ToString(bDeviceToken).Replace("-", "").ToLower().Trim();
                                            //Make sure we have a good feedback tuple
                                            if (deviceToken.Length == 64 && Timestamp > minTimestamp)
                                            {
                                                SYLogger.Log("Feedback " + deviceToken);
                                                result = deviceToken;
                                            }
                                            //Clear  array to reuse it
                                            Array.Clear(buffer, 0, buffer.Length);
                                           //Read the next feedback
                                           recd = sslStreamF.Read(buffer, 0, buffer.Length);
                            }
                SYLogger.Log("Reading Ended");
                }

            }

        }
        catch (Exception e)
        {
            SYLogger.Log("Authentication failed - closing the connection::" + e);
            return "NOAUTH";
        }
        finally
        {
            // The client stream will be closed with the sslStream
            // because we specified this behavior when creating the sslStream.
            if (sslStreamF != null) sslStreamF.Close();
            if (tcpClientF != null) tcpClientF.Close();
            //Clear array on error
            Array.Clear(buffer, 0, buffer.Length);
        }
        SYLogger.Log("Feedback ended ");
        return result;
    }

I am developing an iPhone App that uses Apple Push Notifications. On the iPhone side everything is fine, on the server side I have a problem. Notifications are sent correctly however when I try to query the feedback service to obtain a list of devices from which the App has been uninstalled, I always get zero results. I know that I should obtain one result as the App has been uninstalled from one of my test devices. After 24 hours and more I still have no results from the feedback service..

Any ideas? Does anybody know how long it takes for the feedback service to recognize that my App has been uninstalled from my test device?

Note: I have another push notification applications on the device so I know that my app is not the only app.

The code - C#:

    public static string CheckFeedbackService(string certaName, string hostName)
    {
        SYLogger.Log("Check Feedback Service Started");
        ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
         // Create a TCP socket connection to the Apple server on port 2196
        TcpClient tcpClientF = null;
        SslStream sslStreamF = null;
        string result = string.Empty;
         //Contect to APNS& Add the Apple cert to our collection
        X509Certificate2Collection certs = new X509Certificate2Collection { GetServerCert(certaName) };
        //Set up
        byte[] buffer = new byte[38];
        int recd = 0;
        DateTime minTimestamp = DateTime.Now.AddYears(-1);
        // Create a TCP socket connection to the Apple server on port 2196
        try
        {
            using (tcpClientF = new TcpClient(hostName, 2196))
            {
                SYLogger.Log("Client Connected  ::" + tcpClientF.Connected);
                // Create a new SSL stream over the connection
                sslStreamF = new SslStream(tcpClientF.GetStream(), true,ValidateServerCertificate);
                // Authenticate using the Apple cert
                sslStreamF.AuthenticateAsClient(hostName, certs, SslProtocols.Default, false);
                SYLogger.Log("Stream Readable ::" + sslStreamF.CanRead);
                SYLogger.Log("Host Name ::"+hostName);
                SYLogger.Log("Cert Name ::" + certs[0].FriendlyName);

                if (sslStreamF != null)
                {
                    SYLogger.Log("Connection Started");

                            //Get the first feedback
                            recd = sslStreamF.Read(buffer, 0, buffer.Length);
                            SYLogger.Log("Buffer length ::" + recd);
                            //Continue while we have results and are not disposing
                            while (recd > 0)
                            {

                                        SYLogger.Log("Reading Started");
                                            //Get our seconds since 1970 ?
                                            byte[] bSeconds = new byte[4];
                                            byte[] bDeviceToken = new byte[32];
                                            Array.Copy(buffer, 0, bSeconds, 0, 4);
                                            //Check endianness
                                            if (BitConverter.IsLittleEndian)
                                                    Array.Reverse(bSeconds);
                                            int tSeconds = BitConverter.ToInt32(bSeconds, 0);
                                            //Add seconds since 1970 to that date, in UTC and then get it locally
                                            var Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tSeconds).ToLocalTime();
                                            //Now copy out the device token
                                            Array.Copy(buffer, 6, bDeviceToken, 0, 32);
                                            string deviceToken = BitConverter.ToString(bDeviceToken).Replace("-", "").ToLower().Trim();
                                            //Make sure we have a good feedback tuple
                                            if (deviceToken.Length == 64 && Timestamp > minTimestamp)
                                            {
                                                SYLogger.Log("Feedback " + deviceToken);
                                                result = deviceToken;
                                            }
                                            //Clear  array to reuse it
                                            Array.Clear(buffer, 0, buffer.Length);
                                           //Read the next feedback
                                           recd = sslStreamF.Read(buffer, 0, buffer.Length);
                            }
                SYLogger.Log("Reading Ended");
                }

            }

        }
        catch (Exception e)
        {
            SYLogger.Log("Authentication failed - closing the connection::" + e);
            return "NOAUTH";
        }
        finally
        {
            // The client stream will be closed with the sslStream
            // because we specified this behavior when creating the sslStream.
            if (sslStreamF != null) sslStreamF.Close();
            if (tcpClientF != null) tcpClientF.Close();
            //Clear array on error
            Array.Clear(buffer, 0, buffer.Length);
        }
        SYLogger.Log("Feedback ended ");
        return result;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╭ゆ眷念 2024-10-18 05:50:51

您是否尝试向已卸载的应用程序发送推送通知?据我了解,反馈服务仅发送推送通知发送失败的通知。

Did yo try sending a push notification to the uninstalled application? From my understanding, the feedback service only sends notices of failed push notification delivery.

卖梦商人 2024-10-18 05:50:51

卸载后一分钟,您将收到反馈。

In one minute after uninstall, you will receive the feedback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文