You can use the Device.Permissions object to check for checking or requesting access to the following device elements.
Example
The following checks if a permission is already granted. But it does not request the user for it:
{
...
}
Which can also be reached with the following shortcut extension method:
{
...
}
{
...
}
// OR THE SHORTCUT WAY:
if (await DevicePermission.Microphone.Request() == PermissionRequest.Granted)
{
....
}
If you want to access any of the device sensitive information and hardware (such as user location, camera, etc) you should ensure you have access before you do that.
Example:
{
if (await DevicePermission.Camera.Request() != PermissionResult.Granted) return;
// ...
}
Alternatively in M# settings of the Button (or menu item) set "Required Permissions" to "Camera" and the above code will be generated.
When the app feature using the permission needs to be subtle and not annoy the user with a permission dialog, then use Check(). This is usually relevant to optional features.
But if the feature is critical and you don't mind disturbing the user and ask for permission, use Request().
The following permissions are also available for processing on Android only.
For using these, your relevant app code should be wrapped in ANDROID symbol definition only. For example:
#if ANDROID
if (await DevicePermission.WriteCallLog.Request() == PermissionRequest.Granted) { ...}
#endif
...
Starting in iOS 10, nearly all APIs that require requesting authorization require a new key value pair to describe their usage in the Info.plist. Learn more.