Search code examples
iphonemobiletitaniumpush

Titanium push recovering iPhone


I have an application on titanium and I wonder how to recover push from apple in my app.

The finality is to open specific window according to the push data when the app open after notification click.

Regards,


Solution

  • I find alone : Titanium.Network.registerForPushNotifications is called after the resume if the resumed come from click on notification. I think it's best way at this time.

    app.globals.is_resumed = true; // where app.globals is your globals object in app
    
    Titanium.Network.registerForPushNotifications({
        types:[
            Titanium.Network.NOTIFICATION_TYPE_BADGE,
            Titanium.Network.NOTIFICATION_TYPE_ALERT,
            Titanium.Network.NOTIFICATION_TYPE_SOUND
              ],
        success: successCallback,
        error: errorCallback,
        callback: function(notif) {
                 // you can use notif.data ..
                 if (app.globals.is_resumed === false) {
                    // application is launch on notification click
                 } else {
                    // application is already launch when notification pop
                 }
            }
    });
    
    Titanium.App.addEventListener('pause', function() {
        app.globals.is_resumed = true;
    });
    
    Titanium.App.addEventListener('resumed', function(e) {
            app.globals.is_resumed = false;
    });