C# 使用PushSharp将通知排入队列时,根本不会发生任何事情
我尝试用PushSharp库发送Apple推送通知,如下所示:C# 使用PushSharp将通知排入队列时,根本不会发生任何事情,c#,ios,apple-push-notifications,pushsharp,C#,Ios,Apple Push Notifications,Pushsharp,我尝试用PushSharp库发送Apple推送通知,如下所示: public class Push { private readonly PushBroker _push; private static Push _instance; public static Push Instance { get { return _instance ?? (_instance = new Push()); } } public Push
public class Push
{
private readonly PushBroker _push;
private static Push _instance;
public static Push Instance
{
get { return _instance ?? (_instance = new Push()); }
}
public Push()
{
_push = new PushBroker();
_push.OnNotificationSent += new NotificationSentDelegate(_push_OnNotificationSent);
_push.OnNotificationFailed += new NotificationFailedDelegate(_push_OnNotificationFailed);
_push.OnServiceException += new ServiceExceptionDelegate(_push_OnServiceException);
_push.OnChannelCreated += new ChannelCreatedDelegate(_push_OnChannelCreated);
_push.OnChannelDestroyed += new ChannelDestroyedDelegate(_push_OnChannelDestroyed);
_push.OnChannelException += new ChannelExceptionDelegate(_push_OnChannelException);
_push.OnNotificationRequeue += new NotificationRequeueDelegate(_push_OnNotificationRequeue);
_push.RegisterAppleService(new ApplePushChannelSettings(false, File.ReadAllBytes(@"C:\PathToCertificate\Name.p12"), "***"), "myAppId", new PushServiceSettings()
{
Channels = 1,
AutoScaleChannels = false
});
}
void _push_OnNotificationRequeue(object sender, NotificationRequeueEventArgs e)
{
Debug.Print("requeue");
}
void _push_OnChannelException(object sender, IPushChannel pushChannel, Exception error)
{
Debug.Print("channel exception");
}
void _push_OnChannelDestroyed(object sender)
{
Debug.Print("channel destroyed");
}
void _push_OnChannelCreated(object sender, IPushChannel pushChannel)
{
Debug.Print("channel created");
}
void _push_OnServiceException(object sender, System.Exception error)
{
Debug.Print("service exception");
}
void _push_OnNotificationFailed(object sender, INotification notification, System.Exception error)
{
Debug.Print("failed");
}
void _push_OnNotificationSent(object sender, INotification notification)
{
Debug.Print("sent");
}
public void Send(Notification notification)
{
_push.QueueNotification(notification);
_push.StopAllServices("biz.sintek.Rotapost", true);
}
public void SendAppleNotification(string deviceToken, string text)
{
Send(new AppleNotification()
.ForDeviceToken(deviceToken)
.WithAlert(text)
.WithSound("default"));
}
}
我正在调用SendAppleNotification
方法。它不会在任何时间返回,但不会抛出异常,不会调用事件,不会发送通知,也不会接收通知。
我正在使用转换为.p12格式的开发人员推送证书。
仔细检查配置文件。
QueueNotification
PushBroker类的方法是通用的。它使用泛型类型参数来标识用于发送通知的服务
解决方案是将
newapplenotification()…
直接传递到QueueNotification
QueueNotification
类的PushBroker
方法是泛型的。它使用泛型类型参数来标识用于发送通知的服务
解决方案是将newapplenotification()…
直接传递到QueueNotification