How to tell app was started by tapping push messag

2019-05-23 02:12发布

问题:

I have a Worklight app that receives push notifications from the server. A notification means there are new messages for the current user from other users. A user would read them by visiting a messages page within the app and then proceeding to a particular conversation page.

I would like to differentiate in the code between user intentions. The app would:

  1. If the user started the app normally (not by tapping a new notification), present the user with the regular app home screen.
  2. If the user started/resumed the app by tapping a notification, present the user with the messages page.
  3. If received while the app is on foreground, only update the on-screen message count (regardless of which page is active).

The question is: is there a reliable means to differentiate between the above conditions?

In another thread, I saw a suggestion to remember the timestamp of a resume event and an onReadyToSubscribe event and assume we were asleep/inactive if notification arrives e.g. just a second after this. This would enable me to differentiate between 2 and 3.

However, 1 is not covered by this. I.e. if there have been new messages, but the user started the app normally, the app would have no means of knowing this and would think it was started by tapping a notification. This way, the user intended to see app home screen, but we transfer him to the messages page.

Is there a reliable way around this for both iOS and Android?

Worklight vesion 6.2.0.00-20140922-2259.

回答1:

In a pure Native application, you can know "where from the user opened the app", meaning whether it was by tapping on a received notification or by tapping the application icon.

In a Worklight-based Hybrid application, and if using only the JavaScript API, this is not feasible because all paths arrive to the same destination which is the pushNotificationReceived function. So whether you tapped a notification or the app icon or brought the app to the foreground, the aforementioned function will be invoked.


The solution may be to base your implementation on the following Knowledge Center documentation topic: Using native and JavaScript push APIs in the same app.

This way, using a combination of native code and JS code, you could handle the scenario where a notification was received but the user decided to tap the application icon rather than the notification.

An end-to-end example would to somewhat involved to implement, but if you'll follow the code examples in the documentation topic, you should get there...