From 9ee22f76a081b5b9ea5ac52c60129873fcde0da1 Mon Sep 17 00:00:00 2001 From: Ondrej Rehacek Date: Thu, 7 Mar 2024 02:08:51 +0100 Subject: [PATCH] DeeplinkHandler logging and exceptions. --- Assets/Stash/Scripts/Core/StashClient.cs | 2 - .../StashSamples/Scripts/DeeplinkHandler.cs | 38 +++++++++++++------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Assets/Stash/Scripts/Core/StashClient.cs b/Assets/Stash/Scripts/Core/StashClient.cs index 1d72d2d..922f66e 100644 --- a/Assets/Stash/Scripts/Core/StashClient.cs +++ b/Assets/Stash/Scripts/Core/StashClient.cs @@ -130,8 +130,6 @@ public async Task 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(result.Data); return resultResponse; } diff --git a/Assets/StashSamples/Scripts/DeeplinkHandler.cs b/Assets/StashSamples/Scripts/DeeplinkHandler.cs index 514b04f..b3b27f8 100644 --- a/Assets/StashSamples/Scripts/DeeplinkHandler.cs +++ b/Assets/StashSamples/Scripts/DeeplinkHandler.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using Stash.Core; +using Stash.Core.Exceptions; using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; @@ -9,22 +10,23 @@ 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 @@ -32,8 +34,8 @@ private void Awake() 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]; @@ -41,17 +43,29 @@ private async void onDeepLinkActivated(string url) { //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); + } } } - } \ No newline at end of file