[OneSignal Plugin] Deeplink to specific screen with parameter

[OneSignal Plugin] Deeplink to specific screen with parameter

  
Forge Component
(5)
Published on 27 Apr by OutSystems R&D
5 votes
Published on 27 Apr by OutSystems R&D

In the SendPushNotification is a parameter Deeplink; how can i use this parameter to redirect to a specific screen (with parameter) when the notification is clicked?

To be more specific:

Server side:

- I added a PushNotificationDeepLink to the SendPushNotification with parameter key / value pair (task / 1)

App side:

- I added the OneSignal widget to the Layout with a OnNotificaitonOpened / OnNotificationReceived Event Handler


When i send a notification and open it; these events are not triggered? Did I miss something?


I am having exactly the same issue

Also, having a deep link or not makes no difference, the triggers wont work either way

Cipriano Teibão wrote:

Also, having a deep link or not makes no difference, the triggers wont work either way

That's my conclusion too


Created a support case for this issue

Hey, guys,

I have been tackling this case with Matthias and have replied on another thread, concerning the events not triggering.

If you're experiencing that specific problem, would you please let me know if this solved it for you?

Best regards,

Carlos Simões

So every time a screen loads the app calls the Register action? That doesn't seem optimized at all...


From what I could find, what is hapenning is that the event listeners for some reason are lost, if you add the event listeners it works fine. I do not know if this is the right solution, but it is working fine so far.


1- Create a new action on the plugin eSpace.

2- Place the following code in that action:


require(["OneSignalPluginManager"], function(oneSignalMgr){
   
    var builder = window.plugins.OneSignal.startInit($parameters.ApiKey);
    builder.handleNotificationReceived(oneSignalMgr.notificationReceivedDelegate);
    builder.handleNotificationOpened(oneSignalMgr.notificationOpenedDelegate);
    builder.inFocusDisplaying($parameters.InFocusDisplayOption);
   
    // Set your iOS Settings
    var iosSettings = {};
    iosSettings["kOSSettingsKeyAutoPrompt"] = true;
    iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;
   
    builder.iOSSettings(iosSettings);
   
    builder.endInit();
   
    $resolve();
   
});


3- Use the new action on the onready event of the layout block.


https://www.screencast.com/t/eU0KI7H5


Should work just fine.


PS: Only tested on Android

Cipriano Teibão wrote:

2- Place the following code in that action:


require(["OneSignalPluginManager"], function(oneSignalMgr){
   
    var builder = window.plugins.OneSignal.startInit($parameters.ApiKey);
    builder.handleNotificationReceived(oneSignalMgr.notificationReceivedDelegate);
    builder.handleNotificationOpened(oneSignalMgr.notificationOpenedDelegate);
    builder.inFocusDisplaying($parameters.InFocusDisplayOption);
   
    // Set your iOS Settings
    var iosSettings = {};
    iosSettings["kOSSettingsKeyAutoPrompt"] = true;
    iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;
   
    builder.iOSSettings(iosSettings);
   
    builder.endInit();
   
    $resolve();
   
});


Hi Cipriano,

Your solution looks promising so I tried to implement it. However I get stuck on the two parameters the JavaScript requires: ApiKey and InFocusDisplayOption. Which data types should these be and which values should be used?

Hope you can help me take the next step.

Thanks!

Frans Moquette



Hi,


1 - Your onesignal ApiKey.

2 - Its a value from the static entity 'InFocusDisplayOption' we have it as NOTIFICATION


Regards,

Cipriano

Cipriano Teibão wrote:

1 - Your onesignal ApiKey.

2 - Its a value from the static entity 'InFocusDisplayOption' we have it as NOTIFICATION

Hi Cipriano,

Thanks. I got my app to compile and I thought your solution worked, because I had the OnNotificationReceived event triggered. But alas, it was triggered only once! On all subsequent push messages nothing happened like before. I tried some variations and discovered something really weird: a push notification will trigger the OnNotificationReceived event exactly once after the app has been recompiled and updated to the latest version on the mobile device. Any subsequent notifications do not trigger the events.

So what is wrong? I created a Client Action in the OneSignal plugin exactly by your example with input parameters ApiKey and InfocusDisplayOption. The client action is called from OnReady of the Layout block with the parameters properly filled. The Layout block also contains the OneSignal plugin in a container and the OnNotificationReceived and OnNotificationOpened event handlers. The Layout block is used for every screen in the mobile app.

Any suggestions on what I could do different?



Hi Everyone,

Outsystems provided me with what they call a 'temporary workaround' that works for us. Their workaround is as follows.

"I think I found something which may explain the behavior. Allow me to explain:

  1. The OneSignal block's Destroy handler removes the Received and Opened event handlers when it runs;
  2. This is done because Client actions from the block are called when handling these events; but after a transition to a new screen, actions from the previous screen can't be called anymore (doing so will trigger an error on the console/Service Center stating so);
  3. Unfortunately, the Destroy event is triggered after the next screen's Ready event, meaning EVERY plugin event handler will be lost (see this link for a clear timeline of screen lifecycle events).

We are currently discussing what is the best way to solve this, but in the meantime, what I propose as a temporary workaround is that the Destroy event handler be disabled from the OneSignal block.


Allow me to reiterate the steps, now including this temporary workaround:

  1. Place the 'OneSignal' block on the 'Layout', under the 'layout' container; I believe you have done this as the screenshot clearly depicts it;
  2. Make sure the handler of the 'Ready' event calls either 'Register' or 'RegisterWithUser' actions, in addition to other existing calls; I didn't mention this step explicitly in my last communication, but since the device is receiving notifications, you should already be doing it;
  3. Open the 'OneSignalPlugin' module, select the 'OneSignal' block and choose '(None)' as its 'OnDestroy' handler, as depicted on ; don't forget to publish the module and refresh the references of the consuming app."


The actual solution for us was step 3, the other things were already in place in one way or another.

Hope this info is useful for others with the same problem.


Hi Frans,

Thank you for step-by-step instruction for solving this issue. However I'm still having errors on console when notification is received or clicked:

Controller [2017-07-18T13:37:09.627Z]: Invalid call of the 'OnNotificationReceived' client action of the 'MainFlow.HomePage' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action.
undefined.


Hello, Mykola,

Looking at the proposed solution, I believe this is a side-effect of the workaround: since we are removing the logic that removes the event handlers, if you navigate to a screen that doesn't include the 'OneSignal' block, it will try to call the previous screen's handlers (and trigger this error).

As long as you use the OneSignal block on all screens for the moment, the handlers will be re-set and the error will not be triggered.

If you do feel something is up, however, please do let us know!

Best regards,

Carlo Simões

I edited the build Deeplink action in the API module to include a new input parameter which is a "PageName" and then amend the logic to add this too the DeepLink variable.  You will then get something along the lines of com.outsystems.appname/AppName/PageName.  Without making this change I was getting errors too.

Dan

Hi Everyone,

We have (finally) been able to create a working solution with the OneSignal plugin using Cipriano Teibão's solution. One important thing, the Javascript parameter called 'ApiKey' is improperly named, it should have been named 'OneSignalAppId' and the value of your OneSignalAppId should be passed into the action.

Because of the name for this parameter we initially used the OneSignalRestApiKey-value in our call to this action and our app did not work on Android (phones would not stay subscribed with OneSignal). The issue only presented itself with Android phones, iOS phones worked perfectly fine from the start. It took us many weeks and the help of Outsystems support (thanks again Carlo Simões) to discover that the OneSignalAppId-value had to be passed into the action instead.

Hopes this helps anyone still having issues implementing the OneSignal plugin.

Frans