当前位置: 首页 > 编程语言 > C#

ApplePushNotification和APNSSharp分享

时间:2023-04-11 01:09:04 C#

ApplePushNotification和APNSSharp我使用的是ApplePushNotification的APNSSharp库。我从这里下载.i使用APNSsharp库提供的示例测试程序,没有任何修改。在我在那行代码处设置断点之前,它不会发送任何通知。如果我想出一个突破点。我只是工作得很好。这是预期的行为,还是我做错了什么。而且我也没有得到任何例外。感谢您的帮助。这是代码staticvoidMain(string[]args){boolsandbox=true;stringtestDeviceToken="令牌";字符串p12File="apn_developer_identity.p12";stringp12FilePassword="你的密码";intsleepBetweenNotifications=15000;字符串p12Filename=System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,p12File);NotificationServiceservice=newNotificationService(sandbox,p12Filename,p12FilePassword,1);服务.SendRetries=5;服务.ReconnectDelay=5000;//5秒service.Error+=newNotificationService.OnError(service_Error);service.NotificationTooLong+=newNotificationService.OnNotificationTooLong(service_NotificationTooLong);service.BadDeviceToken+=newNotificationService.OnBadDeviceToken(service_BadDeviceToken);service.NotificationFailed+=newNotificationService.OnNotificationFailed(service_NotificationFailed);service.NotificationSuccess+=newNotificationService.OnNotificationSuccess(service_NotificationSuccess);服务ce.Connecting+=newNotificationService.OnConnecting(service_Connecting);service.Connected+=newNotificationService.OnConnected(service_Connected);service.Disconnected+=newNotificationService.OnDisconnected(service_Disconnected);通知alertNotification=newNotification(testDeviceToken);警报通知。Payload.Alert.Body="测试{0}...";alertNotification.Payload.Sound="默认";alertNotification.Payload.Badge=i;if(service.QueueNotification(alertNotification))Console.WriteLine("通知排队!");elseConsole.WriteLine("通知排队失败!");Console.WriteLine("清理中...");service.Close();//如果我不在此处设置断点,它不会发送任何通知service.Dispose();我希望我的问题很清楚......更新:我被困在这里任何人都可以帮助我。我发现了问题。这是APNSSHARP库的线程工作流程中的错误。编辑:我在排队所有通知后调用此方法。像service.start();这是方法publicvoidSend(){foreach(NotificationConnectionconninthis.notificationConnections){//Console.Write("StartSending");conn.start(P12File,P12FilePassword);我也看到了这个。查看NotificationConnection.Close()方法,我发现://在这里休眠以防止竞争条件//当工作线程//在其循环后休眠时,通知可以排队,但如果我们在100毫秒内将关闭设置为true,那么在这段时间内排队的通知不会因为closed=true而出队,因为循环//将退出;//在我们停止接受Thread.Sleep(250)以上时间后,250毫秒应该足够了,以便循环出现任何剩余的通知//在提到的循环中,我发现:Thread.Sleep(500);将关闭方法中的睡眠时间设置为1000对我来说已修复;)-答案:http://code.google.com/p/apns-sharp/issues/detail?id=41以上是C#学习教程:ApplePushNotification和APNS瑞丽分享的全部内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: