Skip To Content

PermissionDialog QML Type

(BETA) Provides a dialog to authorize the use of device capabilities. More...

Import Statement: import ArcGIS.AppFramework.Platform 1.0

Properties

Signals

Methods

Detailed Description

The PermissionDialog component provides the ability to force a dialog on mobile devices, asking for the user to authorize a specific capability of the device. In most cases, QML components that call for certain capabilities provide access to these permissions by themselves, but in cases where this doesn't happen, your app will face issues if PermissionDialog isn't used to control capability authorization.

The capability you're attempting to authorize must be enabled in the Capabilities tab of the Settings tool to use this component in an app.

This functionality is supported on all platforms. However on iOS, there is also an app store requirement to add usage description keys into the appinfo.json file to explain why your app is requesting to use any permissions it's asking for.

This code sample demonstrates the functionality of PermissionDialog, providing a button that gives the user a dialog for enabling location services.

Item {
    property bool locationPermissionGranted

    PermissionDialog {
        id: permissionDialog
        openSettingsWhenDenied: true
        permission: PermissionDialog.PermissionDialogTypeLocationWhenInUse

        onAccepted: {
            console.log("Permission accepted")
            locationPermissionStatusText.text = "Location Permission Status: " + permissionStatusToString()
        }

        onRejected: {
            console.log("Permission rejected")
            locationPermissionStatusText.text = "Location Permission Status: " + permissionStatusToString()
        }
    }

    Column {
        Button {
            text: qsTr("Request Location Permission")
            visible: !locationPermissionGranted
            onClicked: {
                if (locationPermissionGranted === false) {
                    permissionDialog.open()
                }
            }
        }

        Label {
            id: locationPermissionStatusText
            text: qsTr("Location Permission Status: ") + permissionStatusToString()
        }
    }

    // convert permission status to string
    function permissionStatusToString() {
        switch (Permission.checkPermission(Permission.PermissionTypeLocationWhenInUse)) {
        case Permission.PermissionResultGranted:
            return "Granted";
        case Permission.PermissionResultDenied:
            return "Denied";
        case Permission.PermissionResultRestricted:
            return "Restricted";
        case Permission.PermissionResultUnknown:
            return "Unknown";
        }
    }

    Component.onCompleted: {
        // check if location permission is granted
        locationPermissionGranted = Permission.checkPermission(Permission.PermissionTypeLocationWhenInUse) === Permission.PermissionResultGranted
    }
}

Enumerations

PermissionDialogType enumeration

Enum describing the permission that the dialog is attempting to enable. Informs the permission property.

NameValue
PermissionDialog.PermissionDialogTypeBluetooth0
PermissionDialog.PermissionDialogTypeCamera1
PermissionDialog.PermissionDialogTypeMicrophone2
PermissionDialog.PermissionDialogTypeLocationWhenInUse3
PermissionDialog.PermissionDialogTypeLocationAlwaysInUse4
PermissionDialog.PermissionDialogTypeStorage5

Property Documentation

openSettingsWhenDenied : bool

When this property is set to true, your device's settings will be opened if the user declines the permission prompt.

It is not recommended to use this property when the app is initialized.


permission : PermissionDialogType

The capability permission that the dialog is asking to enable. Informed by the PermissionDialogType enum. If this property is not provided, it will default to a prompt for location when the app is in use.


Signal Documentation

accepted()

Signal emitted when the user has accepted the request to enable a capability.


rejected()

Signal emitted when the user has declined the request to enable a capability.


Method Documentation

open()

Opens the permission dialog, prompting the user to either accept or decline turning on the capability defined by the permission property.