Beispiel #1
0
    IEnumerator RequestPermissions()
    {
        // wait for the first frame...
        yield return(null);

        var receiver = PermissionCallbackReceiver.GetPermissionCallbackReceiver();

        if (Debug.isDebugBuild)
        {
            Debug.Log("Showing permissions explanation...");
        }

        if (Debug.isDebugBuild)
        {
            Debug.Log("Requesting CAMERA permission...");
        }
        receiver.EnsureRequiredPermission(PermissionCallbackReceiver.CAMERA_PERMISSION, cameraPermissionRequiredTitle, cameraPermissionRequiredMessage, permissionInstructionsAfterNeverAskAgainOrHomeOut, () =>
        {
            hasCameraPermission = true;
            googleAnalytics.LogEvent("Permissions", "Camera", "True", 1);
        });

        while (!hasCameraPermission.HasValue || hasCameraPermission.Value == false)
        {
            yield return(null);
        }

        if (Debug.isDebugBuild)
        {
            Debug.Log("All permissions granted.");
        }

        AllPermissionsGranted = true;
    }
Beispiel #2
0
    IEnumerator CheckSharePermissionsCoroutine()
    {
        viewManager.ShowUploadingView();
        yield return(new WaitForSeconds(0.3f));

        permissionsResult = true;

        // first we need to check for permissions...
        var receiver = PermissionCallbackReceiver.GetPermissionCallbackReceiver();

        if (Application.platform == RuntimePlatform.Android)
        {
            // Check for CONTACTS permissions
            if (receiver.HasPermission(PermissionCallbackReceiver.CONTACTS_PERMISSION))
            {
                Debug.Log("CONTACTS permission already granted");
            }
            else
            {
                hasContactsPermission = null;
                Debug.Log("Requesting CONTACTS permission");

                // this will set hasContactsPermission to true or false
                receiver.RequestPermission(PermissionCallbackReceiver.CONTACTS_PERMISSION);

                // wait for positive or negative response
                while (!hasContactsPermission.HasValue)
                {
                    yield return(null);
                }

                if (hasContactsPermission.Value == false)
                {
                    // the user denied the contacts permision...
                    viewManager.ShowContactPermissionErrorView();
                    permissionsResult = false;
                    yield break;                     // stop the co-routine
                }
            }

            // Create a DrivePermissionsResult to sattisfy compiler
            DrivePermissionsResult drivePermissionResult = new DrivePermissionsResult
            {
                failed       = true,
                failedReason = "No result",
                failureType  = DriveFailureType.GenericFailure,
            };

            // Check permissions on Google Drive
            yield return(driveReceiver.CheckPermissionsCoroutine((DrivePermissionsResult result) => {
                drivePermissionResult.failed = result.failed;
                drivePermissionResult.failedReason = result.failedReason;
                drivePermissionResult.failureType = result.failureType;
                drivePermissionResult.accountName = result.accountName;
            }));


            if (drivePermissionResult.failed)
            {
                Debug.LogError("Spray drive permission failed: " + drivePermissionResult);
                googleAnalytics.LogEvent("Spray", "Share error", "Spray drive permission failed: " + drivePermissionResult, 1);

                switch (drivePermissionResult.failureType)
                {
                case DriveFailureType.DrivePermissionIssue:
                    viewManager.ShowAccountProhibited();
                    break;

                case DriveFailureType.NoConnection:
                    viewManager.ShowBadConnection(true);
                    break;

                case DriveFailureType.AuthCanceled:
                    viewManager.ShowDriveAuthFailed(true);
                    break;

                case DriveFailureType.AuthFailed:
                    viewManager.ShowDriveAuthFailed(true);
                    break;

                default:
                    // generic error handling for now
                    viewManager.ShowUploadFailed(true);
                    break;
                }
                permissionsResult = false;
            }
        }
        else if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            // Create a DrivePermissionsResult to sattisfy compiler
            DrivePermissionsResult drivePermissionResult = new DrivePermissionsResult
            {
                failed       = true,
                failedReason = "No result",
                failureType  = DriveFailureType.GenericFailure,
            };

            // Check permissions on Google Drive
            yield return(driveReceiver.CheckPermissionsCoroutine((DrivePermissionsResult result) => {
                drivePermissionResult.failed = result.failed;
                drivePermissionResult.failedReason = result.failedReason;
                drivePermissionResult.failureType = result.failureType;
                drivePermissionResult.accountName = result.accountName;
            }));

            if (drivePermissionResult.failed)
            {
                Debug.LogError("Spray drive permission failed: " + drivePermissionResult);
                googleAnalytics.LogEvent("Spray", "Share error", "Spray drive permission failed: " + drivePermissionResult, 1);

                switch (drivePermissionResult.failureType)
                {
                case DriveFailureType.DrivePermissionIssue:
                    viewManager.ShowAccountProhibited();
                    break;

                case DriveFailureType.NoConnection:
                    viewManager.ShowBadConnection(true);
                    break;

                case DriveFailureType.AuthCanceled:
                    viewManager.ShowDriveAuthFailed(true);
                    break;

                default:
                    // generic error handling for now
                    viewManager.ShowUploadFailed(true);
                    break;
                }
                permissionsResult = false;
            }
        }
        else
        {
            if (fakeContactFailure)
            {
                Debug.Log("Faking contact failure in editor");
                viewManager.ShowContactPermissionErrorView();
                permissionsResult = false;
                yield break;                 // stop the co-routine
            }
            else
            {
                Debug.Log("Skipping CONTACTS permission request on this platform: " + Application.platform.ToString());
            }
        }
    }