使用PushSharp排队通知时根本没有任何事情发生

时间:2015-06-04 08:14:10

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

1 个答案:

答案 0 :(得分:0)

QueueNotification类的

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

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