如何使用 c# 在 ios 上发送通知

Posted

技术标签:

【中文标题】如何使用 c# 在 ios 上发送通知【英文标题】:how to send notification on ios using c# 【发布时间】:2017-04-25 03:05:03 【问题描述】:

我正在使用下面提到的这段代码,但出现错误:

指定的参数超出了有效值的范围。 参数名称:您的证书不是连接苹果APNS服务器的有效证书

我想使用 asp.net MVC 向 ios 设备发送通知。我正在使用 push sharp 库来发送通知。

【问题讨论】:

【参考方案1】:

给你,如果你的证书是 Prod/Dev,你也需要注意 取决于 ApplePushChannelSettings 方法中的第一个参数是 true= 如果证书是生产 false = 如果证书正在开发中

broker = new PushBroker();
broker.OnNotificationSent += _broker_OnNotificationSentApple;
broker.OnChannelException += _broker_OnChannelExceptionApple;
broker.OnServiceException += _broker_OnServiceExceptionApple;
broker.OnNotificationFailed += _broker_OnNotificationFailedApple;
broker.OnDeviceSubscriptionExpired += _broker_OnDeviceSubscriptionExpiredApple;
broker.OnDeviceSubscriptionChanged += _broker_OnDeviceSubscriptionChangedApple;
broker.OnChannelCreated += _broker_OnChannelCreatedApple;
broker.OnChannelDestroyed += _broker_OnChannelDestroyedApple;


byte[] appleCert = File.ReadAllBytes(the path to the certificate);
broker.RegisterAppleService(new PushSharp.Apple.ApplePushChannelSettings(false,appleCert, appCertPassword,false),null);/

broker.QueueNotification(new AppleNotification()
                         .ForDeviceToken(yourDeviceToken)
                         .WithAlert(message)
                         .WithBadge(0));

【讨论】:

以上是关于如何使用 c# 在 ios 上发送通知的主要内容,如果未能解决你的问题,请参考以下文章