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
 public static void DispatchDialogClosed()
 {
     if (PermissionCallbackReceiver.DialogClosed != null)
     {
         PermissionCallbackReceiver.DialogClosed();
     }
 }
Beispiel #3
0
 public static void DispatchPermissionRequestStatus(string perm, bool granted)
 {
     if (PermissionCallbackReceiver.PermissionRequestStatus != null)
     {
         PermissionCallbackReceiver.PermissionRequestStatus(perm, granted);
     }
 }
Beispiel #4
0
    public void DialogCallback(string noOp)
    {
        if (Debug.isDebugBuild)
        {
            Debug.Log("DialogCallback(noOp) called from iOS");
        }

        PermissionCallbackReceiver.DispatchDialogClosed();
    }
Beispiel #5
0
    public void PermissionCallback(string res)
    {
        if (Debug.isDebugBuild)
        {
            Debug.Log("PermissionCallback('" + res + "') called from iOS");
        }

        string[] parts   = res.Split(',');
        string   perm    = parts[0];
        bool     granted = false;

        bool.TryParse(parts[1], out granted);

        KnownPermissions[perm] = granted;

        PermissionCallbackReceiver.DispatchPermissionRequestStatus(perm, granted);
    }
Beispiel #6
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());
            }
        }
    }