代码之家  ›  专栏  ›  技术社区  ›  Nnp

APNS夏普苹果推送通知

  •  3
  • Nnp  · 技术社区  · 16 年前

    我使用APNS夏普库的苹果推送通知。我是从 Here
    如果我把断点。我只是工作很好。这是预期的行为还是我做错了什么。我也没有得到任何例外。谢谢你的帮助。 这是密码

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

    我希望我的问题很清楚。。。
    我被困在这里了。请任何人都能帮我。

    2 回复  |  直到 16 年前
        1
  •  2
  •   Nnp    15 年前

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


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

         public void Send()
        {
            foreach (NotificationConnection conn in this.notificationConnections)
            {
               // Console.Write("Start Sending");
                conn.start(P12File, P12FilePassword);
            }
        }
    
        2
  •  1
  •   theiOSDude    15 年前

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

    //在其中,当工作线程 //在循环后休眠,但如果我们在100毫秒内设置为真, //在此期间排队的通知将不会作为循环退出队列 //将因关闭而退出=真; //在我们停止接受上面的内容之后 睡眠(250);

    睡眠(500);

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