【问题标题】:apple push notification with APNS sharp带有 APNS 锐利的苹果推送通知
【发布时间】:2010-07-01 22:14:16
【问题描述】:

我使用 APNS Sharp 库作为我的苹果推送通知。我已经从Here下载了。我使用APNS sharp库提供的示例测试程序,没有任何修改。
它根本不会发送任何通知,直到我在该代码行放置断点。 如果我放断点。我工作正常。这是预期的行为还是我做错了什么。而且我也没有任何例外。谢谢你的帮助。 这是代码

static void Main(string[] args)
{
    bool sandbox = true;
    string testDeviceToken = "Token";
    string p12File = "apn_developer_identity.p12";
    string p12FilePassword = "yourpassword";
    int sleepBetweenNotifications = 15000;
    string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);
    NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);
    service.SendRetries = 5; 
    service.ReconnectDelay = 5000; //5 seconds
    service.Error += new NotificationService.OnError(service_Error);
    service.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);
    service.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
    service.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
    service.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
    service.Connecting += new NotificationService.OnConnecting(service_Connecting);
    service.Connected += new NotificationService.OnConnected(service_Connected);
    service.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
    Notification alertNotification = new Notification(testDeviceToken);
    alertNotification.Payload.Alert.Body = "Testing {0}...";
    alertNotification.Payload.Sound = "default";
    alertNotification.Payload.Badge = i;
    if (service.QueueNotification(alertNotification))
      Console.WriteLine("Notification Queued!");
    else
      Console.WriteLine("Notification Failed to be Queued!");
    Console.WriteLine("Cleaning Up...");

    service.Close();// if i dont put a break point in here, it simply does not send any notification

    service.Dispose();

}

我希望我的问题很清楚......
更新:我被困在这里。请任何人都可以帮助我。

【问题讨论】:

  • 只是检查:你确实有你的证书,对吧?您的证书密码是“您的密码”吗?只是想知道这是否是示例中遗留的内容。
  • 感谢 ACBurk。是的,我有。如果我设置断点,它就可以正常工作。

标签: c# iphone push-notification apple-push-notifications apns-sharp


【解决方案1】:

我发现了问题。这是 APNS SHARP 库线程工作流中的错误。

编辑:
我在排队所有通知后调用此方法。
喜欢
service.start();
这是方法

     public void Send()
    {
        foreach (NotificationConnection conn in this.notificationConnections)
        {
           // Console.Write("Start Sending");
            conn.start(P12File, P12FilePassword);
        }
    }

【讨论】:

  • 什么意思?什么错误?我在 vb.net 中使用一些库代码来推送到 apns。我得到“通知排队”,但通知从未发送到设备......这怎么可能?
  • 当您说 NotificationService service = new NotificationService() 时,它会启动另一个从队列中读取的线程。但是在您将任何通知添加到队列之前,由于没有通知,该线程已经终止。有意义>如果你设置断点,那么监听器线程将不会完成,因为它正在等待断点。
  • 基本上我最终在 NotificationService 中创建了另一个名为“Send”的方法,该方法“启动”发送实际通知的线程。创建 NotificationService 对象时会调用此“开始”方法。这是错误的。如果您需要更多解释,请告诉我。我还添加了代码
【解决方案2】:

我也看到了。查看 NotificationConnection.Close() 方法,我发现:

// 在这里休眠以防止竞争条件 // 通知可以在工作线程时排队 // 在其循环之后处于休眠状态,但如果我们在 100 毫秒内设置关闭为真, // 在那段时间排队的通知不会因为循环而出队 // 将因关闭而退出 = true; // 250 毫秒应该是足够的时间让循环出列任何剩余的通知 // 在我们停止接受上面之后 线程.睡眠(250);

在提到的循环中我发现: 线程.睡眠(500);

将 close 方法中的睡眠时间设置为 1000 为我修复了它;) - 来自:http://code.google.com/p/apns-sharp/issues/detail?id=41 的回答

【讨论】:

    猜你喜欢
    • 2014-01-08
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 2011-05-19
    • 2010-12-01
    • 1970-01-01
    相关资源
    最近更新 更多