private IEnumerator <bool> RegisterForAndroidPushNotificationsCoroutine() { Firebase.Messaging.FirebaseMessaging.TokenReceived += this.OnTokenReceived; Firebase.Messaging.FirebaseMessaging.MessageReceived += this.OnMessageReceived; int retryCount = 0; while (this.deviceToken == null) { retryCount++; if (retryCount >= RetryCountMax) { yield break; } // Waiting before we retry again... float waitTime = 0.0f; while (waitTime < RetryWaitTime) { yield return(default(bool)); waitTime += UnityEngine.Time.deltaTime; } } var register = PF.Do(new PlayFab.ClientModels.AndroidDevicePushNotificationRegistrationRequest { DeviceToken = this.deviceToken }); while (register.IsDone == false) { yield return(default(bool)); } if (register.HasError) { var playfabError = register.Exception as PlayFabException; if (playfabError != null) { UnityEngine.Debug.Log("Error Registering for Android Push Notifications!"); UnityEngine.Debug.Log(playfabError.Error.Error); UnityEngine.Debug.Log(playfabError.Error.ErrorMessage); UnityEngine.Debug.Log(playfabError.Error.ErrorDetails); } } else { // Saving that we've registed this user for PushNotifications with PlayFab successfully LostPlayerPrefs.GetString(HasRegisteredUserForPushNotificationsKey, PF.User.PlayFabId); UnityEngine.Debug.Log("Push Notification Registration Successful!"); yield return(true); } yield return(true); }
private static void SetCurrentLanguage() { if (currentLanguage != null) { return; } string currentLanguageName = LostPlayerPrefs.GetString(CurrentLanguageKey, null); if (currentLanguageName == null) { // This is the first time running the app, so the language has never been // set, so determining the language based on the device's SystemLanguage. foreach (var language in GetSupportedLanguages()) { if (language.SystemLanguage == UnityEngine.Application.systemLanguage) { currentLanguage = language; SaveCurrentLangauge(); UpdateI2Localization(); return; } } } else { // Looking up the Language by the name we last saved in LostPlayerPrefs foreach (var language in GetSupportedLanguages()) { if (language.IsoLanguageName == currentLanguageName) { currentLanguage = language; UpdateI2Localization(); return; } } } // If we got here, then we failed to find the right language, so returning the default currentLanguage = DefaultLanguage; SaveCurrentLangauge(); UpdateI2Localization(); }
private IEnumerator <bool> RegisterForIosPushNotificationsCoroutine() { var notifications = UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound; UnityEngine.iOS.NotificationServices.RegisterForNotifications(notifications, true); int retryCount = 0; while (this.deviceToken == null) { if (this.deviceToken == null && UnityEngine.iOS.NotificationServices.deviceToken != null) { this.deviceToken = System.BitConverter.ToString(UnityEngine.iOS.NotificationServices.deviceToken).Replace("-", "").ToLower(); } retryCount++; if (retryCount >= RetryCountMax) { yield break; } // Waiting before we retry again... float waitTime = 0.0f; while (waitTime < RetryWaitTime) { yield return(default(bool)); waitTime += UnityEngine.Time.deltaTime; } } // if we got here and still no deviceToken, then we timed out if (this.deviceToken == null) { UnityEngine.Debug.LogError("PlayFabIOSPushHandler timed out waiting for the deviceToken."); // cleaning up this iOS push notification handler so it doesn't take up any cycles yield break; } string registeredUser = LostPlayerPrefs.GetString(HasRegisteredUserForPushNotificationsKey, null); // Checking if we're already successfully registed this user with PlayFab for push notifications if (registeredUser == PF.User.PlayFabId) { CoroutineRunner.Instance.StartCoroutine(this.CheckForIosPushNotificationsCoroutine()); yield return(true); yield break; } var register = PF.Do(new PlayFab.ClientModels.RegisterForIOSPushNotificationRequest { DeviceToken = this.deviceToken }); while (register.IsDone == false) { yield return(default(bool)); } if (register.HasError) { var playfabError = register.Exception as PlayFabException; if (playfabError != null) { UnityEngine.Debug.Log("Error Registering for iOS Push Notifications!"); UnityEngine.Debug.Log(playfabError.Error.Error); UnityEngine.Debug.Log(playfabError.Error.ErrorMessage); UnityEngine.Debug.Log(playfabError.Error.ErrorDetails); } } else { // Saving that we've registed this user for PushNotifications with PlayFab successfully LostPlayerPrefs.GetString(HasRegisteredUserForPushNotificationsKey, PF.User.PlayFabId); CoroutineRunner.Instance.StartCoroutine(this.CheckForIosPushNotificationsCoroutine()); UnityEngine.Debug.Log("Push Notification Registration Successful!"); yield return(true); } }