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