コード例 #1
0
    private void CheckPushStatus()
    {
        if (string.IsNullOrEmpty(pushToken))
        {
            return;
        }

#if UNITY_ANDROID && !UNITY_EDITOR
        var androidRequest = new AndroidDevicePushNotificationRegistrationRequest {
            DeviceToken = pushToken
        };
        PlayFab.PlayFabClientAPI.AndroidDevicePushNotificationRegistration(androidRequest, null, null);
#elif UNITY_IPHONE && !UNITY_EDITOR
        var iosRequest = new RegisterForIOSPushNotificationRequest {
            DeviceToken = pushToken
        };
        PlayFab.PlayFabClientAPI.RegisterForIOSPushNotification(iosRequest, null, null);
#endif
    }
コード例 #2
0
    private void RegisterForPush()
    {
        if (string.IsNullOrEmpty(pushToken) || string.IsNullOrEmpty(playFabId))
        {
            return;
        }

#if UNITY_ANDROID
        var request = new AndroidDevicePushNotificationRegistrationRequest {
            DeviceToken = pushToken
        };
        PlayFabClientAPI.AndroidDevicePushNotificationRegistration(request, OnPfAndroidReg, OnPfFail);
#elif UNITY_IOS
        var request = new RegisterForIOSPushNotificationRequest {
            DeviceToken = pushToken
        };
        PlayFabClientAPI.RegisterForIOSPushNotification(request, OnPfIosReg, OnPfFail);
#endif
    }
コード例 #3
0
    public static void RegisterForPushNotification(string pushToken = null, UnityAction callback = null)
    {
#if UNITY_EDITOR || UNITY_EDITOR_OSX
        if (callback != null)
        {
            callback();
            return;
        }
#endif

#if UNITY_IPHONE
        string hexToken = string.Empty;
        byte[] token    = UnityEngine.iOS.NotificationServices.deviceToken;
        if (token != null)
        {
            RegisterForIOSPushNotificationRequest request = new RegisterForIOSPushNotificationRequest();
            request.DeviceToken = BitConverter.ToString(token).Replace("-", "").ToLower();

            hexToken = request.DeviceToken;
            Debug.Log(hexToken);

            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.RegisterForPush);
            PlayFabClientAPI.RegisterForIOSPushNotification(request, result =>
            {
                if (callback != null)
                {
                    callback();
                }
                PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.RegisterForPush, MessageDisplayStyle.none);
            }, PF_Bridge.PlayFabErrorCallback);
        }
        else
        {
            Debug.Log("Push Token was null!");
        }
#endif

#if UNITY_ANDROID
        if (!string.IsNullOrEmpty(pushToken))
        {
            Debug.Log("GCM Init Success");
            var request = new AndroidDevicePushNotificationRegistrationRequest {
                DeviceToken = pushToken
            };

            DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.RegisterForPush);
            PlayFabClientAPI.AndroidDevicePushNotificationRegistration(request, result =>
            {
                if (callback != null)
                {
                    callback();
                }
                PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.RegisterForPush, MessageDisplayStyle.none);
            }, PF_Bridge.PlayFabErrorCallback);
        }
        else
        {
            Debug.Log("Push Token was null or empty: ");
        }
#endif
    }
コード例 #4
0
 public static IEnumerator <RegisterForIOSPushNotificationResult> Do(RegisterForIOSPushNotificationRequest request)
 {
     return(Do <RegisterForIOSPushNotificationRequest, RegisterForIOSPushNotificationResult>(request, PlayFabClientAPI.RegisterForIOSPushNotification));
 }
コード例 #5
0
    private const string ANDROID_PUSH_SENDER_ID = "718447176723"; // TODO: Use your own FCM SenderId

    public void Start()
    {
#if UNITY_IOS || UNITY_IPHONE
        UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound, true);
#endif

#if UNITY_ANDROID
        PlayFabAndroidPushPlugin.OnGcmSetupStep += OnGcmSetupSteps;
        PlayFabAndroidPushPlugin.OnGcmMessage   += OnGcmMessage;
        PlayFabAndroidPushPlugin.Init();
#endif

        var device_id = SystemInfo.deviceUniqueIdentifier;
#if UNITY_ANDROID
        AndroidJavaClass  up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject currentActivity = up.GetStatic <AndroidJavaObject>("currentActivity");
        AndroidJavaObject contentResolver = currentActivity.Call <AndroidJavaObject>("getContentResolver");
        AndroidJavaClass  secure          = new AndroidJavaClass("android.provider.Settings$Secure");
        device_id = secure.CallStatic <string>("getString", contentResolver, "android_id");

        var req = new LoginWithAndroidDeviceIDRequest()
        {
            AndroidDevice   = SystemInfo.deviceModel,
            AndroidDeviceId = device_id,
            OS                    = SystemInfo.operatingSystem,
            TitleId               = PlayFabSettings.TitleId,
            CreateAccount         = true,
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams()
            {
                GetUserInventory = true
            }
        };
        PlayFabClientAPI.LoginWithAndroidDeviceID(req, (result) => {
            Debug.Log("Login With Android Successful");
            PlayFabAndroidPushPlugin.TriggerManualRegistration();

            PlayFabClientAPI.GetCatalogItems(new GetCatalogItemsRequest()
            {
                CatalogVersion = "Items"
            }, (catalogResult) => {
                IAPService.CatalogItems = catalogResult.Catalog;
                IAPService.InitializePurchasing();

                var itemCount      = result.InfoResultPayload.UserInventory.Count;
                ItemCountText.text = string.Format("{0}", itemCount);
            }, null);
        }, ErrorCallback);
#endif
#if Unity_IOS || UNITY_IPHONE
        var req = new LoginWithIOSDeviceIDRequest()
        {
            DeviceId              = device_id,
            DeviceModel           = SystemInfo.deviceModel,
            OS                    = SystemInfo.operatingSystem,
            TitleId               = PlayFabSettings.TitleId,
            CreateAccount         = true,
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams()
            {
                GetUserInventory = true
            }
        };
        PlayFabClientAPI.LoginWithIOSDeviceID(req, (result) => {
            Debug.Log("Login With IOS Successful");

            string hexToken = string.Empty;
            byte[] token    = UnityEngine.iOS.NotificationServices.deviceToken;
            if (token != null)
            {
                RegisterForIOSPushNotificationRequest request = new RegisterForIOSPushNotificationRequest();
                request.DeviceToken = System.BitConverter.ToString(token).Replace("-", "").ToLower();
                hexToken            = request.DeviceToken;
                Debug.Log(hexToken);
                PlayFabClientAPI.RegisterForIOSPushNotification(request, null, null);
            }
            else
            {
                Debug.Log("Push Token was null!");
            }

            PlayFabClientAPI.GetCatalogItems(new GetCatalogItemsRequest()
            {
                CatalogVersion = "Items"
            }, (catalogResult) => {
                IAPService.CatalogItems = catalogResult.Catalog;
                IAPService.InitializePurchasing();

                var itemCount      = result.InfoResultPayload.UserInventory.Count;
                ItemCountText.text = string.Format("{0}", itemCount);
            }, null);
        }, null);
#endif
    }
コード例 #6
0
 public UnityTask <RegisterForIOSPushNotificationResult> Do(RegisterForIOSPushNotificationRequest request)
 {
     return(this.Do <RegisterForIOSPushNotificationRequest, RegisterForIOSPushNotificationResult>(request, PlayFabClientAPI.RegisterForIOSPushNotificationAsync));
 }