/// <summary> /// Attached to the button's clicked event. /// </summary> public void OnClick() { #if !UNITY_EDITOR //if it's not visible, either load the logged in flow, or login screen based on the token's presence if (!SampleWebView.webViewObject.GetVisibility()) { RewardMob.instance.ToggleLoadingScreen(true); SampleWebView.Init(); SampleWebView.webViewObject.LoadURL(RewardMobEndpoints.GetWebViewURL()); } #endif }
/// <summary> /// Method used for communication from iOS/Android -> Unity for passing a valid authentication token /// /// NOT INTENDED TO BE MANUALLY CALLED WITHIN UNITY /// </summary> /// <param name="tokenFragment">The token</param> public void OnAccessToken(string tokenFragment) { string[] keyValues = tokenFragment.Split('&'); foreach (string keyValuePair in keyValues) { string[] keyValue = keyValuePair.Split('='); //invalid KVP if (keyValue.Length != 2) { continue; } string key = keyValue[0]; string value = keyValue[1]; switch (key) { case "access_token": RewardMob.instance.Token = value; break; case "expires_in": double expirationInSeconds = (double)long.Parse(value); RewardMob.instance.TokenExpiration = DateTime.UtcNow.AddSeconds(expirationInSeconds - reauthenticationOffsetInSeconds).ToString(); break; default: break; } } //if this isn't part of the reauth process, open the WebView if (!isReauthenticating) { SampleWebView.webViewObject.LoadURL(RewardMobEndpoints.GetWebViewURL()); } #if UNITY_IOS // Tell iOS to Close the SafariViewController. _CloseSafari(); #endif isReauthenticating = false; RewardMob.instance.TotalRewardCount = 0; }
/// <summary> /// Pop open a WebView for when an unauthorized user earns a Reward for the first time (Onboarding) /// </summary> private void ShowFirstTimeEarnedRewardScreen() { #if !UNITY_EDITOR if ((earnedState == RewardMobAuthorizedState.NOT_EARNED_FIRST_REWARD) && (Token == null)) { ToggleLoadingScreen(true); SampleWebView.Init(); try { SampleWebView.webViewObject.LoadURL(RewardMobEndpoints.GetWebViewURL(useLogicalRewards: true)); earnedState = RewardMobAuthorizedState.EARNED_FIRST_REWARD; } catch { Debug.LogError("Fill out the Game ID section inside of the RewardMobData object at RewardMobSDK/Resources."); } } #endif }
public void RefreshWebview() { SampleWebView.webViewObject.LoadURL(RewardMobEndpoints.GetWebViewURL()); }