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);
        }
Пример #2
0
 public void Save()
 {
     if (this.IsDirty)
     {
         this.IsDirty = false;
         LostPlayerPrefs.SetInt(this.volumeKey, (int)(this.volume * 100));
         LostPlayerPrefs.SetBool(this.isMutedKey, this.isMuted);
         LostPlayerPrefs.Save();
     }
 }
        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);
            }
        }
Пример #4
0
 public void Load()
 {
     this.volume  = LostPlayerPrefs.GetInt(this.volumeKey, (int)(this.defaultVolume * 100)) / 100.0f;
     this.isMuted = LostPlayerPrefs.GetBool(this.isMutedKey, this.defaultIsMuted);
 }
Пример #5
0
 public void ResetAnonymousId()
 {
     LostPlayerPrefs.DeleteKey(AnonymousIdKey);
     LostPlayerPrefs.Save();
 }