c# - 带有 APNS sharp 的苹果推送通知

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

我将 APNS Sharp 库用于我的苹果推送通知。我已经从Here下载了.i使用APNS sharp library提供的示例测试程序,没有任何修改。
它只是不发送任何通知,直到我在该行代码处放置断点。 如果我设置断点。我工作得很好。这是预期的行为还是我做错了什么。而且我也没有任何异常(exception)。谢谢你的帮助。 这是代码

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();

}

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

最佳答案

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

编辑:
我在排队所有通知后调用此方法。
喜欢
服务启动();
这是方法

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

关于c# - 带有 APNS sharp 的苹果推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3162076/

相关文章:

ios - 如何在收到推送通知后刷新 watchkit 界面 Controller

c# - 在 OOP 中覆盖方法与分配方法委托(delegate)/事件

c# - 如何使用这个脚本?

iphone - xcode iOS CoreData 简单关系数据检索

ios - 当 react native 应用程序未在 ios 设备上启动时如何调试

android - 在 GCM 服务器上设置计划的推送通知

amazon-web-services - 适用于 Web 应用程序的 AWS 推送通知服务

c# - 如何从 Windows 平板电脑 UWP 应用程序使用数据库?

c# - 使用 Entity Framework 在 Windows Azure 中播种成员资格

iphone - 从 UINavigationController 设置 UITabBarItem 标题?