Redth / PushSharp

A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, Windows 8, Amazon, Blackberry, and (soon) FirefoxOS devices!
Other
4.39k stars 1.52k forks source link

The events handler in older versions no more available in latest version. #749

Open sitangruan opened 7 years ago

sitangruan commented 7 years ago

What version of PushSharp are you using?

I was using 2.2.1, now I am upgrading to 4.0

Describe your issue:

My previous codes in 2.2.1 are like this PushBroker push = new PushBroker();

    //Wire up the events for all the services that the broker registers
    push.OnNotificationSent  += NotificationSent;
    push.OnChannelException  += ChannelException;
    push.OnServiceException  += ServiceException;
    push.OnNotificationFailed  += NotificationFailed;
    push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
    push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
    push.OnChannelCreated  += ChannelCreated;
    push.OnChannelDestroyed  += ChannelDestroyed;

In that way I could handle a lot of events/exceptions, specially like DeviceSubscriptionExpired DeviceSubscriptionChanged.

However after upgrade to 4.0, the new broker object has only Succeed/Failed events provided so the codes are like this, var broker = new ApnsServiceBroker(config); broker.OnNotificationFailed += (notification, exception) => { failed++; }; broker.OnNotificationSucceeded += (notification) => { succeeded++; };

So how can I see those few other events/exceptions which were available in older version? Is there any work around?

What are the steps required to reproduce this issue?

None

Please provide any Exception Stack Traces

None

SteveLobdell commented 7 years ago

Copy pasted from the readme file, this prints the exception to the console.

// Wire up events
apnsBroker.OnNotificationFailed += (notification, aggregateEx) => {

    aggregateEx.Handle (ex => {

        // See what kind of exception it was to further diagnose
        if (ex is ApnsNotificationException) {
            var notificationException = (ApnsNotificationException)ex;

            // Deal with the failed notification
            var apnsNotification = notificationException.Notification;
            var statusCode = notificationException.ErrorStatusCode;

            Console.WriteLine ($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");

        } else {
            // Inner exception might hold more useful information like an ApnsConnectionException           
            Console.WriteLine ($"Apple Notification Failed for some unknown reason : {ex.InnerException}");
        }

        // Mark it as handled
        return true;
    });
};

Copy pasted from Exception.cs

   public enum ApnsNotificationErrorStatusCode
    {
        NoErrors = 0,
        ProcessingError = 1,
        MissingDeviceToken = 2,
        MissingTopic = 3,
        MissingPayload = 4,
        InvalidTokenSize = 5,
        InvalidTopicSize = 6,
        InvalidPayloadSize = 7,
        InvalidToken = 8,
        Shutdown = 10,
        ConnectionError = 254,
        Unknown = 255
    }