private IEnumerator Start()
        {
            PlayFabGoogleCloudMessaging._RegistrationCallback += (token, error) => { this.deviceToken = token; };

            PlayFabGoogleCloudMessaging._MessageCallback += (message) => { this.pushHandler.ReceivedPushNotification(message); };

            PlayFabGoogleCloudMessaging._RegistrationReadyCallback += (status) =>
            {
                if (status)
                {
                    PlayFabGoogleCloudMessaging.GetToken();     // request device token
                    PlayFabAndroidPlugin.UpdateRouting(false);  // suppress push notifications while app is running
                }
            };

            // TODO [bgish]:  This should probably be located in AppSettings, if not defined print error and early out GameObject.Destroy(this);
            PlayFabAndroidPlugin.Init("GoogleAppId");

            int retryCount = 0;

            while (this.deviceToken == null)
            {
                retryCount++;

                if (retryCount >= RetryCountMax)
                {
                    break;
                }

                yield return(new WaitForSeconds(RetryWaitTime));
            }

            // if we got here and still no deviceToken, then we timed out
            if (this.deviceToken == null)
            {
                Debug.LogError("PlayFabAndroidPushHandler timed out waiting for the RegistrationCallback to complete.");

                // cleaning up this Android push notification handler so it doesn't take up any cycles
                GameObject.Destroy(this);
                yield break;
            }

            PlayFabClientAPI.AndroidDevicePushNotificationRegistration(
                new AndroidDevicePushNotificationRegistrationRequest {
                DeviceToken = this.deviceToken
            },
                (result) =>
            {
                Debug.Log("Push Notification Registration Successful!");
            },
                (error) =>
            {
                Debug.Log("Error Registering for Android Push Notifications!");
                Debug.Log(error.Error);
                Debug.Log(error.ErrorMessage);
                Debug.Log(error.ErrorDetails);
            });
        }
示例#2
0
 public static void OnGCMReady(bool status)
 {
     Debug.Log("GCM Ready!");
     PlayFabGoogleCloudMessaging.GetToken();
 }
示例#3
0
 public void OnGCMReady(bool status)
 {
     Debug.Log("AccountStatusController: GCM Ready!");
     PlayFabGoogleCloudMessaging.GetToken();
 }