Skip to content

[Question] How to not re-trigger a Dynamic link? / How to check for pending links on app focus? #969

Closed
@RobinopdeBeek

Description

@RobinopdeBeek

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.2.3
  • Firebase Unity SDK version: 7.0.2
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Dynamic Links
  • Other Firebase Components in use: Auth, Database, Firestore, Storage, Analytics, Cloud Functions
  • Additional SDKs you are using:
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: Android (iOS in the future)
  • Scripting Runtime: IL2CPP

[REQUIRED] Please describe the question here:

When I click on a dynamic link it opens the app and goes to the correct page (very cool stuff btw, thanks!). But when I put the app to the background and then reopen it, it re-triggers the dynamic link (and going to the page again). This also happens when I close the Android keyboard after typing stuff.
So how can I let my app know that the link was already used and shouldn't be used again? Can I dispose the Received Dynamic Link in some way? Why would it keep triggering anyway?

Here is my code that receives the dynamic link:

public static class DynamicLinksManager 
{      
        private static bool isInitialized = false;

        // Gets called on Start after authentication has been setup.
        // Also gets called OnApplicationPause(false)
        public static void InitializeLinks()
        {
            if (!isInitialized)
            {
                Debug.Log("Initialized Dynamic Links");
                isInitialized = true;
                DynamicLinks.DynamicLinkReceived += OnDynamicLink;
            }
        }
       
        // Gets called OnApplicationPause(true)
        public static void DeinitializeLinks()  
        {
            if (isInitialized)
            {
                isInitialized = false;
                DynamicLinks.DynamicLinkReceived -= OnDynamicLink;
            }
        }

        private static void OnDynamicLink(object sender, EventArgs args)
        {
            var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
            var deeplink = dynamicLinkEventArgs.ReceivedDynamicLink.Url;
            Debug.Log("Received dynamic link: " + dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
            
            if (!deeplink.OriginalString.Contains("?ProjectID="))
            { 
                Debug.Log("Deeplink does not contain a ProjectID");
                return;
            }

            string projectID = GetProjectIDFromUrl(deeplink.OriginalString, "?ProjectID=");
            Debug.Log("Project ID received from link: " + projectID);

            GotoProject(projectID);
        }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions