Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Titanium.Network.registerForPushNotifications never call back if you switch off all notification for a titanium app

$
0
0

Hi,

Why is that Titanium.Network.registerForPushNotifications never call back if you switch off all notification for a titanium app in the Notification Center?

So, for now this is how I do it. Since I observed that the registerForPushNotifications can return very fast.

var deviceToken, cancelled = false;

Titanium.Network.registerForPushNotifications({
    types: [
        Titanium.Network.NOTIFICATION_TYPE_BADGE,
        Titanium.Network.NOTIFICATION_TYPE_ALERT,
        Titanium.Network.NOTIFICATION_TYPE_SOUND
    ],
    success:function(e)
    {
        if (logger.is_debug_enabled) logger.logDebug("Successfully registered for push! e: " + JSON.stringify(e));

        deviceToken = chain.bucket.device_token_from_cloud = e.deviceToken;

        if (!cancelled) {
            cancelled = true;
            callback(deviceToken);
        }
    },
    error:function(e)
    {
        if (logger.is_error_enabled) logger.logError("Error: " + e.message);

        if (!cancelled) {
            cancelled = true;
            callback(deviceToken);
        }
    },
    callback:function(e)
    {
        if (logger.is_debug_enabled) logger.logDebug("push notification received "+JSON.stringify(e.data));

        handle_notification_event_from_cloud(e.data);
    }
});

setTimeout(function() {
    if (!deviceToken && !cancelled) {
        cancelled = true;
        callback(deviceToken);
    }
}, 1000);

So, is there any better to do it?


Viewing all articles
Browse latest Browse all 8068

Trending Articles



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