当使用PushSharp排队通知时,什么都不会发生

本文关键字:什么 PushSharp 排队 通知 | 更新日期: 2023-09-27 17:53:08

我尝试用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()
    {
        _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格式的开发人员推送证书。双重检查配置文件

当使用PushSharp排队通知时,什么都不会发生

PushBroker类的QueueNotification方法是通用的。它使用泛型类型参数来标识要用于通知发送的服务。

解决方案是将new AppleNotification()...直接传递给QueueNotification