How do I know if an application was opened or resumed as a result of a push notification in Titanium?

How do you handle push differently in Titanium depending on whether the application was open at the time of arrival?

When a push notification arrives and my application is running, I would like to open a message suggesting to transmit to the user the element to which the notification relates. If the application is closed and the user clicks on the push notification and forces the application to open, I would like to take the user directly to the element without a popup.

The titanium register ForPushNotifications seems to have only one callback, a “callback” that is called regardless of the state of the application when a push arrives. According to How do I know if my iPhone application works when I receive a push notification? you can use didReceiveRemoteNotification and didFinishLaunchingWithOptions in Objective-C, but Titanium doesn't seem to provide separate access to them.

+5
source share
1 answer

The callback function will be launched immediately after the “resume” if the user comes from a notification.

So, I would handle your case as follows:

, , (a la var is_paused = false; ). is_paused true "" Ti.App - (1 ) Ti.App.

, , is_paused var :

//in notification callback
if(is_paused){ 
   //user is coming from background (do your thing automatically)
}else{
  //user is in app (display the alert)
}
+1

All Articles