• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

c# - 从版本 4.0.10.0 到 Testflight 的 PushSharp Apple 通知问题

[复制链接]
菜鸟教程小白 发表于 2022-12-12 11:12:11 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我创建了一个生产版本 .p12 文件来将通知发送到 iPhone,并使用 testflight 安装了应用程序。

从我的示例控制台应用程序发送通知时,我总是收到通知发送回调,但设备没有收到通知。

我的 Pushsharp 版本是 4.0.10.0 发送通知的代码如下所示:

  public static void SendAppleNotification()
    {
        // Configuration (NOTE: .pfx can also be used here)
        var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, "C:\\Users\\MancMiniUser\\Documents\\visual studio 2013\\Projects\\PushSharpDemo\\PushSharpDemo\\Resources\\P12CertifyPIE.p12", "1234");

        // Create a new broker
        var apnsBroker = new ApnsServiceBroker(config);

        // Wire up events
        apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
        {

            aggregateEx.Handle(ex =>
            {

                // See what kind of exception it was to further diagnose
                if (ex is ApnsNotificationException)
                {
                    var notificationException = (ApnsNotificationException)ex;

                    // Deal with the failed notification
                    var apnsNotification = notificationException.Notification;
                    var statusCode = notificationException.ErrorStatusCode;

                    Console.WriteLine("Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");

                }
                else
                {
                    // Inner exception might hold more useful information like an ApnsConnectionException           
                    Console.WriteLine("Apple Notification Failed for some unknown reason : {ex.InnerException}");
                }

                // Mark it as handled
                return true;
            });
        };

        apnsBroker.OnNotificationSucceeded += (notification) =>
        {
            Console.WriteLine("Apple Notification Sent!");
        };

        // Start the broker
        apnsBroker.Start();


        // Queue a notification to send
        apnsBroker.QueueNotification(new ApnsNotification
        {
            DeviceToken = "3cfcc2ceefe6675d89b063e2e39d03503b3917250e6743d185c755e9e2c3579d",
            Payload = JObject.Parse("{\"aps\":{\"alert\":\"Hello from sourabh v.4.0 Tester.\",\"badge\":\"1\"}}")

        });

        // Stop the broker, wait for it to finish   
        // This isn't done after every message, but after you're
        // done with the broker
        apnsBroker.Stop();
    }

谁能帮我解决这个问题,为什么即使通知发送的回调即将到来,也没有收到通知?



Best Answer-推荐答案


您创建了生产证书,然后用作 ApnsConfiguration.ApnsServerEnvironment.Production

  • var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, "C:\Users\MancMiniUser\Documents\visual studio 2013\Projects\PushSharpDemo\PushSharpDemo\Resources\P12CertifyPIE.p12", "1234");

关于c# - 从版本 4.0.10.0 到 Testflight 的 PushSharp Apple 通知问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37045299/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap