/// <summary>
        /// Initiate an authorization request.
        /// </summary>
        /// <param name="authorizationOption"> The authorization options your app is requesting. You may specify multiple options to request authorization for. Request only the authorization options that you plan to use.</param>
        /// <param name="registerForRemoteNotifications"> Set this to true to initiate the registration process with Apple Push Notification service after the user has granted authorization
        /// If registration succeeds the DeviceToken will be returned. You should pass this token along to the server you use to generate remote notifications for the device. </param>
        public AuthorizationRequest(AuthorizationOption authorizationOption, bool registerForRemoteNotifications)
        {
            iOSNotificationsWrapper.RegisterAuthorizationRequestCallback();
            iOSNotificationsWrapper.RequestAuthorization((int)authorizationOption, registerForRemoteNotifications);

            iOSNotificationCenter.OnAuthorizationRequestCompleted += OnAuthorizationRequestCompleted;
        }
Example #2
0
    IEnumerator RequestAuthorization(AuthorizationOption options = AuthorizationOption.Alert | AuthorizationOption.Badge | AuthorizationOption.Sound)
    {
        var request = new AuthorizationRequest(
            options, true);

        yield return(request);


        Debug.Log("RequestAuthorization");
        using (var req = new AuthorizationRequest(options, true))
        {
            while (!req.IsFinished)
            {
                yield return(null);
            }
            ;

            string res = "\n\n\n RequestAuthorization: \n";
            res += "\n finished: " + req.IsFinished;
            res += "\n granted :  " + req.Granted;
            res += "\n error:  " + req.Error;
            res += "\n deviceToken:  " + req.DeviceToken;

            res += "\n\n\n";
            Debug.Log(res);
        }
    }
 public static void RequestAuthorization(AuthorizationOption authorizationOption)
 {
     try
     {
         RequestPushAuthorizationInternal((int)authorizationOption, AuthorizationRequestResultCallback);
     }
     catch (Exception exception)
     {
         Debug.LogError("RequestAuthorization error: " + exception.Message);
     }
 }
Example #4
0
        private IEnumerator RequestAuthorizationCoroutine(AuthorizationOption authorizationOptions, bool registerForRemoteNotifications)
        {
            using (var request = new AuthorizationRequest(authorizationOptions, registerForRemoteNotifications))
            {
                while (!request.IsFinished)
                {
                    yield return(null);
                }

                _coroutine = null;
                OnAuthorized(request);
            }
        }
        /// <summary>
        /// Initiate an authorization request.
        /// </summary>
        /// <param name="authorizationOption"> The authorization options your app is requesting. You may specify multiple options to request authorization for. Request only the authorization options that you plan to use.</param>
        /// <param name="registerForRemoteNotifications"> Set this to true to initiate the registration process with Apple Push Notification service after the user has granted authorization
        /// If registration succeeds the DeviceToken will be returned. You should pass this token along to the server you use to generate remote notifications for the device. </param>
        public AuthorizationRequest(AuthorizationOption authorizationOption, bool registerForRemoteNotifications)
        {
            iOSNotificationsWrapper.RegisterAuthorizationRequestCallback();
            iOSNotificationsWrapper.RequestAuthorization((int)authorizationOption, registerForRemoteNotifications);

            iOSNotificationCenter.OnAuthorizationRequestCompleted += data =>
            {
                Debug.Log("            iOSNotificationsWrapper.onAuthenticationRequestFinished += data => ");
                IsFinished  = data.finished;
                Granted     = data.granted;
                Error       = data.error;
                DeviceToken = data.deviceToken;
            }
            ;
        }
    public void Setup()
    {
#if UNITY_EDITOR
        originaliOSSDK = PlayerSettings.iOS.sdkVersion;
        originalRequestAuthorizationOnAppLaunch = NotificationSettings.iOSSettings.RequestAuthorizationOnAppLaunch;
        originalAuthorizationOptions            = NotificationSettings.iOSSettings.DefaultAuthorizationOptions;
        originalAddRemoteNotificationCapability = NotificationSettings.iOSSettings.AddRemoteNotificationCapability;
        originalRequestRemoteOnLaunch           = NotificationSettings.iOSSettings.NotificationRequestAuthorizationForRemoteNotificationsOnAppLaunch;

        PlayerSettings.iOS.sdkVersion = iOSSdkVersion.SimulatorSDK;
        NotificationSettings.iOSSettings.RequestAuthorizationOnAppLaunch = true;
        NotificationSettings.iOSSettings.DefaultAuthorizationOptions     = originalAuthorizationOptions | AuthorizationOption.Provisional;
        NotificationSettings.iOSSettings.AddRemoteNotificationCapability = false;
        NotificationSettings.iOSSettings.NotificationRequestAuthorizationForRemoteNotificationsOnAppLaunch = false;
#endif
    }
            AuthorizationOption GetAuthorizationOptions()
            {
                AuthorizationOption options = 0;

                if (this.ycManager.ycConfig.NotifAuthorizationAlert)
                {
                    options |= AuthorizationOption.Alert;
                }
                if (this.ycManager.ycConfig.NotifAuthorizationBadge)
                {
                    options |= AuthorizationOption.Badge;
                }
                if (this.ycManager.ycConfig.NotifAuthorizationSound)
                {
                    options |= AuthorizationOption.Sound;
                }
                return(options);
            }
Example #8
0
    //Request authorization if it is not enabled in Editor UI
    IEnumerator RequestAuthorization(AuthorizationOption options = AuthorizationOption.Alert | AuthorizationOption.Badge | AuthorizationOption.Sound)
    {
        var request = new AuthorizationRequest(
            options, true);

        yield return(request);


        Debug.Log("RequestAuthorization");
        using (var req = new AuthorizationRequest(AuthorizationOption.Alert | AuthorizationOption.Badge, true))
        {
            while (!req.IsFinished)
            {
                yield return(null);
            }

            ;

            string res = "\n\n\n RequestAuthorization: \n";
            res += "\n finished: " + req.IsFinished;
            res += "\n granted :  " + req.Granted;
            res += "\n error:  " + req.Error;
            res += "\n deviceToken:  " + req.DeviceToken;

            res += "\n\n\n";
            Debug.Log(res);
        }


        //This part is needed if one wants to always get the callback of notifications

        /*
         * iOSNotificationCenter.OnNotificationReceived += notification =>
         *  {
         *      Debug.Log("Notification received: ");
         *      Debug.Log(".Title: " + notification.Title);
         *      Debug.Log(".Identifier: " + notification.Identifier);
         *      Debug.Log(".Badge: " + notification.Badge);
         *      Debug.Log(".Body: " + notification.Body);
         *      Debug.Log(".CategoryIdentifier: " + notification.CategoryIdentifier);
         *      Debug.Log(".Subtitle: " + notification.Subtitle);
         *  };
         */
    }
Example #9
0
    IEnumerator RequestAuthorization()
    {
        const AuthorizationOption authorizationOption =
            AuthorizationOption.Alert | AuthorizationOption.Badge | AuthorizationOption.Sound;

        using var req = new AuthorizationRequest(authorizationOption, true);
        while (!req.IsFinished)
        {
            yield return(null);
        }

        string res = "\n RequestAuthorization:";

        res += "\n finished: " + req.IsFinished;
        res += "\n granted :  " + req.Granted;
        res += "\n error:  " + req.Error;
        res += "\n deviceToken:  " + req.DeviceToken;
        Debug.Log(res);
    }
Example #10
0
        //Request authorization if it is not enabled in Editor UI
        IEnumerator RequestAuthorization(AuthorizationOption options)
        {
            m_LOGGER.Blue($"[{DateTime.Now.ToString("HH:mm:ss.ffffff")}] Call {MethodBase.GetCurrentMethod().Name}");
            using (AuthorizationRequest request = new AuthorizationRequest(options, true))
            {
                while (!request.IsFinished)
                {
                    yield return(null);
                }

                if (request.Granted)
                {
                    m_LOGGER
                    .Green($"Authorization request was granted")
                    .Properties(request);
                    Debug.Log(request.DeviceToken);
                }
                else
                {
                    m_LOGGER.Red($"Authorization request was denied");
                }
            }
        }
Example #11
0
        /// <summary>
        /// Initiate an authorization request.
        /// </summary>
        /// <param name="authorizationOption"> The authorization options your app is requesting. You may specify multiple options to request authorization for. Request only the authorization options that you plan to use.</param>
        /// <param name="registerForRemoteNotifications"> Set this to true to initiate the registration process with Apple Push Notification service after the user has granted authorization
        /// If registration succeeds the DeviceToken will be returned. You should pass this token along to the server you use to generate remote notifications for the device. </param>
        public AuthorizationRequest(AuthorizationOption authorizationOption, bool registerForRemoteNotifications)
        {
            var handle = GCHandle.Alloc(this);

            iOSNotificationsWrapper.RequestAuthorization(GCHandle.ToIntPtr(handle), (int)authorizationOption, registerForRemoteNotifications);
        }