androidfirebaseunity-game-enginefirebase-invites

Unity Firebase Invites throws exception ApplicationException: internal::IsInitialized()


I'm trying to add Firebase Invites to my Unity game. I've followed all the tutorial steps and have set up seems like everything. But when I try to run the code from tutorial to send an invite, I'm getting an exception:

ApplicationException: internal::IsInitialized()
 at Firebase.FutureBase.status ()
 at Firebase.Invites.SendInviteFuture.GetTask (Firebase.Invites.SendInviteFuture fu)
 at Firebase.Invites.FirebaseInvites.SendInviteAsync (Firebase.Invites.Invite invite)
...

The code is:

void Start()
{
    Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
    {
        dependencyStatus = task.Result;
        if (dependencyStatus == Firebase.DependencyStatus.Available)
            InitializeFirebase();
        else
            Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
    });
}

void InitializeFirebase()
{
    Firebase.Invites.FirebaseInvites.InviteReceived += OnInviteReceived;
    Firebase.Invites.FirebaseInvites.InviteNotReceived += OnInviteNotReceived;
    Firebase.Invites.FirebaseInvites.ErrorReceived += OnErrorReceived;
}

public void ShowInviteBox(System.Action<bool> callback)
{
  var invite = new Firebase.Invites.Invite() {
    TitleText = "Invites Test App",
    MessageText = "Please try my app! It's awesome.",
    CallToActionText = "Download it for FREE",
    DeepLinkUrl = new System.Uri("http://google.com/abc")
  };
  Firebase.Invites.FirebaseInvites.SendInviteAsync(invite).ContinueWith(HandleSentInvite);
}

I use:

Any help would be highly appreciated!


Solution

  • I think I found a solution.

    That error occurs when use "SendEvent()" before firebase initialized.

    I solved error by below code.

    private void InitializeFirebase()
    {
        Debug.Log("FirebaseManager : Enabling data collection.");
        FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
    
        Debug.Log("FirebaseManager : Set user properties.");
        // Set the user's sign up method.
        FirebaseAnalytics.SetUserProperty(
          FirebaseAnalytics.UserPropertySignUpMethod,
          "Google");
        // Set the user ID.
        FirebaseAnalytics.SetUserId("uber_user_510");
        // Set default session duration values.
        FirebaseAnalytics.SetMinimumSessionDuration(new TimeSpan(0, 0, 10));
        FirebaseAnalytics.SetSessionTimeoutDuration(new TimeSpan(0, 30, 0));
    
        //THIS IS SOLUTION!!!!
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => 
        {
            FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventLogin);
        });
    }
    

    Enter your first "SendEvent" in the CheckAndFixDependenciesAsync().

    Hope this was helpful.


    After I finded and installed Older version of firebase(6.15.2), The older version of firebase showed me a helpful error message...

    "don't call firebase functions before check dependencies has finished"