1

I am required to send statistics if the app was opened or resumed from push notification.

How do I detect it in Titanium?

in particular, on iOS (on Android, I believe that the cgm module I am using has an event)

  • Possible duplicate of http://stackoverflow.com/questions/12057576/how-do-i-tell-if-the-app-was-opened-or-resumed-as-a-result-of-a-push-notificatio?rq=1 Also, you can test for the existence a variable included in your push payload which wouldn't be there if your app was being resumed. – skypanther Mar 10 '16 at 19:54

1 Answers1

0

On iOS, for received notifications (within iOS App and not from lock screen, though they will be triggered when tapped/swiped on from lock screen), you can use the following:

For iOS Remote Notifications: When registering for Push Notifications, use the call back function to listen for all incoming remote notifications.

Ti.Network.registerForPushNotifications({
   success: deviceTokenSuccess, // TODO store the token
   error: deviceTokenError, // TODO
   callback: receivePush // function below
});

function receivePush(e) {
    alert('Received push: ' + JSON.stringify(e));
    // Do what you need for Analytics here
}

For iOS Local Notification with Actions (iOS 8+)

Ti.App.iOS.addEventListener("localnotificationaction",function(){
    //my code
});

For iOS Local Notifications:

Ti.App.iOS.addEventListener('notification',function(){
   // send analytics
});
Yozef
  • 829
  • 11
  • 27