Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (silentpush)
Viewing all articles
Browse latest Browse all 2

silentpush event listener receiving normal push notifications

$
0
0

It seems that the silentpush event handler also receives the normal push notifications. Is this the correct behavior? I expected that the silentpush event handler would receive only the silent push notifications.

Here is my code for the silent push notification handler:

Ti.App.iOS.addEventListener('silentpush', function(e) {
    // If this is not a silent push then call endBackgroundHandler() and return.
    if (_.isUndefined(e.aps["content-available"])) {
        Ti.App.iOS.endBackgroundHandler(e.handlerId);
        return;
    }
 
    // Code that handles the silent push notification.
 
    // Always make sure to call endBackgroundHandler()
    Ti.App.iOS.endBackgroundHandler(e.handlerId);
});
And here is my code for the normal push notification handler:
Ti.Network.registerForPushNotifications({
    types : [Ti.Network.NOTIFICATION_TYPE_BADGE, Ti.Network.NOTIFICATION_TYPE_ALERT, Ti.Network.NOTIFICATION_TYPE_SOUND],
    success : function(e) {
        // Code to save e.deviceToken
    },
    error : function(err, context) {
        // Code to log the error
    },
    callback : function(e) {
        // Code to handle the push notification
    }
});
So when my app receives a normal push notification handler, both the callback registered by Ti.Network.registerForPushNotifications() AND the silentpush event handler are called. This is why I added the code to check if "content-available" is undefined. If content-available is undefined, then it is a normal push.

My code above works for both normal and silent pushes, but I expected the silentpush event handler to be called only when a silent push notification is received.

Two questions: 1) Is this a bug? 2) Is it OK to call Ti.App.iOS.endBackgroundHandler() when the silentpush event handler is called by a normal push? There is a handlerId in the event object in the silentpush event handler, and it seems to work to call Ti.App.iOS.endBackgroundHandler() with that handlerId during a normal push.

Environment: Titanium SDK 3.2.3, Alloy 1.3.1, iOS 7.0 iPad Simulator


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>