使用 PushSharp 排队通知时什么也没有发生

While queueing notifications with PushSharp nothing happens at all

我试过像这样用 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 方法。它 returns 很快但没有抛出异常,没有调用事件,没有发送通知也没有收到通知。 我正在使用转换为 .p12 格式的开发者推送证书。 仔细检查配置文件。

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

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