我正在使用PushSharp版本2.2.1.0,并为iOS引用“PushSharp.Core”和“PushSharp.Apple”库。 我已经删除了防火墙的所有限制,因为它涉及一些安全问题。
我已使用密钥或无密钥从设备导出证书。在发送通知时,我的代码卡在PushBroker类的stopAllServices()方法中。在某些情况下,我设置了ApplePushChannelSettings的SkipSsl = true(我没有使用ssl),我收到错误“提供给包的凭据无法识别“这也是在很久以前发布的:https://code.google.com/p/apns-sharp/issues/detail?id=3。 达到这种方法后,我的程序被绞死了。 这是我的代码:
//Create our push services broker
var push = new PushBroker();
//Wire up the events for all the services that the broker registers
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;
var appleCert = File.ReadAllBytes(FileHelper.CERTIFICATEFILE);
X509Certificate2 Cert = new X509Certificate2(appleCert, FileHelper.PASSWORD, X509KeyStorageFlags.MachineKeySet);
push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, FileHelper.PASSWORD));
push.QueueNotification(new AppleNotification()
.ForDeviceToken(DeviceID.ToUpper()/*my device id*/)
.WithAlert("my message")
.WithSound("default")
.WithBadge(1)
.WithCustomItem("status", new object[] { "sucess") })
.WithCustomItem("identifier", new object[] { "1"}));
push.StopAllServices();
我也尝试过使用没有密码的证书。它触发ChannelCreated并在此之后达到ServiceException。
答案 0 :(得分:0)
我在使用没有密码的证书时发现它有效。