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

Push Notification Callback not fired after App restarted

$
0
0

Hey guys,

I'm using the example source for registering for push notifications on iOS. Titanium SDK 4.1.0GA. When I first install my app on the device and registor for push, the callback "recievePush" is called when I get a push notification. However if I close the app manually and restart it, the callback is not called no more.

Is this a bug with the 4.1.0 SDK?

Here's my code straight from the docs:

function retrievePushTokenAndSubscribe(channel) {
        var deviceToken = null;
        // Check if the device is running iOS 8 or later
        if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
 
         // Wait for user settings to be registered before registering for push notifications
            Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
 
         // Remove event listener once registered for push notifications
                Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush); 
 
                Ti.Network.registerForPushNotifications({
                    success: deviceTokenSuccess,
                    error: deviceTokenError,
                    callback: receivePush
                });
            });
 
         // Register notification types to use
            Ti.App.iOS.registerUserNotificationSettings({
                types: [
                    Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
                    Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
                    Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
                ]
            });
        }
 
        // For iOS 7 and earlier
        else {
            Ti.Network.registerForPushNotifications({
         // Specifies which notifications to receive
                types: [
                    Ti.Network.NOTIFICATION_TYPE_BADGE,
                    Ti.Network.NOTIFICATION_TYPE_ALERT,
                    Ti.Network.NOTIFICATION_TYPE_SOUND
                ],
                success: deviceTokenSuccess,
                error: deviceTokenError,
                callback: receivePush
            });
        }
 
        // Save the device token for subsequent API calls
        function deviceTokenSuccess(e) {
            deviceToken = e.deviceToken;
            Alloy.Globals.persistence.setPushToken(e.deviceToken);
            if (channel) Alloy.Globals.push.subscribeToChannel(channel);
        }
        function deviceTokenError(e) {
            Ti.API.error('Failed to register for push notifications! ' + e.error);
        }
 
}
 
function receivePush(e){
    Ti.API.error(e);
    alert(e);
}

Viewing all articles
Browse latest Browse all 8068

Trending Articles



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