Recognizing a dynamic link when application boots (Unity + iOS)

575 views
Skip to first unread message

Naren Keshav

unread,
Jun 8, 2020, 10:23:16 PM6/8/20
to Firebase Google Group
Target Platform: iOS
Development Tool: Unity3D
Firebase Version: 6.11.0

Scenario
The application is "not running". User presses a dynamic link causing the application to boot.

Intention
When the application boots, how to recognize the dynamic link that the user pressed?

Tryouts
I have an empty scene with default gameobjects & a text mesh pro component. Now I have one script called as DynamicLinkTest.cs on one of the gameobjects

using System;
using TMPro;
using Firebase.DynamicLinks;
using UnityEngine;

namespace Firebase.QA.Tests
{
   
internal sealed class DynamicLinkTest : MonoBehaviour
   
{
       
[SerializeField] internal TextMeshProUGUI MyTextField;
       
private void OnEnable()
       
{
           
DynamicLinks.DynamicLinkReceived += onDynamicLinkReceived;
           
MyTextField.SetText("initiated");
       
}
       
private void onDynamicLinkReceived(object _sender, EventArgs _args)
       
{
           
ReceivedDynamicLinkEventArgs dynamicLinkEventArgs = _args as ReceivedDynamicLinkEventArgs;
           
Debug.LogFormat("Received dynamic link {0}",
                            dynamicLinkEventArgs
.ReceivedDynamicLink.Url.OriginalString);
           
MyTextField.SetText(dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
       
}
       
private void OnDisable()
       
{
           
DynamicLinks.DynamicLinkReceived -= onDynamicLinkReceived;
       
}
   
}
}



 With the above script,
onDynamicLinkReceived()

gets called when the application is in the background (suspended state) but unable to recognize if the application state is "not running".

I hope - I've provided enough information to state my issue. I would love to provide more information for better clarity.

Thank you,
Naren

martin...@google.com

unread,
Jun 16, 2020, 1:06:58 PM6/16/20
to Firebase Google Group
Hi Naren!

You are registering for dynamic links correctly as far as I can tell (there are Unity docs here, and a sample project on GitHub).

I'd love to know whether you believe that you've found a bug in dynamic links (ie: it's not behaving as you expected) or if you're just asking for general device on a specific user journey.

To answer your question directly, in scripts where I care about whether or not I'm in the background I typically use the OnApplicationPause callback. So you could have something like:
```
using System;
using TMPro;
using Firebase.DynamicLinks;
using UnityEngine;

namespace Firebase.QA.Tests
{
    internal sealed class DynamicLinkTest : MonoBehaviour
    {
        [SerializeField] internal TextMeshProUGUI MyTextField;
        private void OnEnable()
        {
            DynamicLinks.DynamicLinkReceived += onDynamicLinkReceived;
            MyTextField.SetText("initiated");
        }
        private void onDynamicLinkReceived(object _sender, EventArgs _args)
        {
            ReceivedDynamicLinkEventArgs dynamicLinkEventArgs = _args as ReceivedDynamicLinkEventArgs;
            Debug.LogFormat("Received dynamic link {0}",
                            dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
            MyTextField.SetText(dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
        }
        private void OnDisable()
        {
            DynamicLinks.DynamicLinkReceived -= onDynamicLinkReceived;
        }
        private void OnApplicationPause(bool paused)
        {
            if (paused)
            {
                // do something here. Set a variable, unregister the callback, &c
            }
            else
            {
                // do something here. Set a variable, register the callback, &c
            }
        }
    }
}
```

If that doesn't help, I just need a little more information about what's happening and what you want to achieve. I can certainly dive into more details (ex: is the callback being triggered in some sort of bad state causing a Unity-level exception of some kind?).

Thanks!
--Patrick

Reply all
Reply to author
Forward
0 new messages