0
我已经开发了在c#中的ios推送通知的代码,但它不是在移动设备中发送通知。 我用过pushsharp库。在c中使用Pushsharp推送通知#
我的代码如下:
PushNotificationApple pushNotification = new PushNotificationApple();
pushNotification.SendNotification(postData);
我PushNotificationApple构造函数的代码如下: -
public PushNotificationApple()
{
if (_pushBroker == null)
{
//Create our push services broker
_pushBroker = new PushBroker();
//Wire up the events for all the services that the broker registers
_pushBroker.OnNotificationSent += NotificationSent;
_pushBroker.OnChannelException += ChannelException;
_pushBroker.OnServiceException += ServiceException;
_pushBroker.OnNotificationFailed += NotificationFailed;
_pushBroker.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
_pushBroker.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
_pushBroker.OnChannelCreated += ChannelCreated;
_pushBroker.OnChannelDestroyed += ChannelDestroyed;
var appleCert = File.ReadAllBytes(System.Web.Hosting.HostingEnvironment.MapPath("~/Certificates" + ConfigSettings.SnaptymAPNSCertificate));
_pushBroker.RegisterAppleService(new ApplePushChannelSettings(false, appleCert,ConfigSettings.SnaptymAPNSPassword)); //Extension method
}
}
我sendNotification的功能如下: -
public bool SendNotification(GcmNotificationPostDataModel postData)
{
if (_pushBroker != null)
{
foreach (var registrationId in postData.RegistrationIds)
{
_pushBroker.QueueNotification(new AppleNotification()
.ForDeviceToken(registrationId) //the recipient device id
.WithAlert(postData.Data.Message) //the message
.WithBadge(1)
.WithSound("sound.caf"));
}
}
return true;
}
您收到了什么错误?您可以在推介人的不同事件中跟踪流程。检查是否有任何异常 – Patel
确保这不是你的情况 http://stackoverflow.com/questions/28499395/apn-production-certificate-not-being-recognized-by-pushsharp – Patel
@patel Good call for生产环境,但目前OP正在发送到沙箱。可以在'new ApplePushChannelSettings(false,....)'的第一个参数中看到,而且这也会引发异常。 – derpirscher