Skip to content

Commit

Permalink
DeeplinkHandler logging and exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliexe committed Mar 7, 2024
1 parent 97382f3 commit 9ee22f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
2 changes: 0 additions & 2 deletions Assets/Stash/Scripts/Core/StashClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ public async Task<LinkResponse> LinkAppleGameCenter(string challenge, string bun
{
try
{
Debug.Log("[STASH] LinkAppleGameCenter successful Response: " + result.Data);
// Parse the response data into a LinkResponse object
LinkResponse resultResponse = JsonUtility.FromJson<LinkResponse>(result.Data);
return resultResponse;
}
Expand Down
38 changes: 26 additions & 12 deletions Assets/StashSamples/Scripts/DeeplinkHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using Stash.Core;
using Stash.Core.Exceptions;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
Expand All @@ -9,49 +10,62 @@ public class DeeplinkHandler : MonoBehaviour
{
public static DeeplinkHandler Instance { get; private set; }
private string stashChallenge;

public GameObject ConfirmPanel;

private void Awake()
{
if (Instance == null)
{
Instance = this;
Application.deepLinkActivated += onDeepLinkActivated;
Instance = this;
Application.deepLinkActivated += OnDeepLinkActivated;
if (!string.IsNullOrEmpty(Application.absoluteURL))
{
// Cold start and Application.absoluteURL not null so process Deep Link.
onDeepLinkActivated(Application.absoluteURL);
OnDeepLinkActivated(Application.absoluteURL);
}
// Initialize DeepLink Manager global variable.
else stashChallenge = "[none]";

DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
private async void onDeepLinkActivated(string url)

private async void OnDeepLinkActivated(string url)
{
//Extract the challenge parameter from the link.
stashChallenge = url.Split("/link?challenge=")[1];
if (!string.IsNullOrEmpty(stashChallenge))
{
//Work with the code challenge, prompt user for confirmation.
Debug.Log("Stash: Deep Link Challenge: " + stashChallenge);

//Get the Game Center Signature, Salt, Timestamp, TeamPlayerID and GamePlayerID from player prefs.
string Signature = PlayerPrefs.GetString("Signature");
string Salt = PlayerPrefs.GetString("Salt");
string Timestamp = PlayerPrefs.GetString("Timestamp");
string TeamPlayerID = PlayerPrefs.GetString("TeamPlayerID");
string PublicKeyURL = PlayerPrefs.GetString("PublicKeyURL");

//Call LinkAppleGameCenter
StashClient.Instance.LinkAppleGameCenter(stashChallenge, "com.Stash.iosdemo", Signature, Salt, PublicKeyURL, TeamPlayerID, Timestamp );

//Call linking function "LinkAppleGameCenter" and pass the parameters.
try
{
await StashClient.Instance.LinkAppleGameCenter(stashChallenge, "com.Stash.iosdemo", Signature, Salt,
PublicKeyURL, TeamPlayerID, Timestamp);
Debug.Log("[STASH] Account linked successfully !");
}
catch (StashAPIRequestError e)
{
Debug.LogWarning("[STASH] Account link failed: " + e.Message);
}
catch (StashParseError e)
{
Debug.LogWarning("[STASH] Failure while parsing the Stash API response: " + e.Message);
}
}
}

}

0 comments on commit 9ee22f7

Please sign in to comment.