Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

A.3. Permission Requirements

Hadi Tavakoli edited this page Aug 2, 2019 · 6 revisions

Permission requirements

Before starting the AR experience in your app, you must make sure you have asked for the required permissions from your users.

The camera permission is always needed but the GPS permission is optional. If you are not planning to use GPS features of AR, you should not ask for its permission at all.

To ask for permissions, you should use this ANE.

private function checkPermissions():void
{
	if(PermissionCheck.check(PermissionCheck.SOURCE_CAMERA) == PermissionCheck.PERMISSION_GRANTED)
	{
		onCameraRequestResult(PermissionCheck.PERMISSION_GRANTED);
	}
	else
	{
		PermissionCheck.request(PermissionCheck.SOURCE_CAMERA, onCameraRequestResult);
	}
	
	function onCameraRequestResult($obj:Object):void
	{
		if($obj.state != PermissionCheck.PERMISSION_GRANTED)
		{
			trace("AR ANE needs Camera access to work properly");
			return;
		}
		
		if(OverrideAir.os == OverrideAir.ANDROID && PermissionCheck.check(PermissionCheck.SOURCE_LOCATION) == PermissionCheck.PERMISSION_GRANTED)
		{
			onLocationRequestResult(PermissionCheck.PERMISSION_GRANTED);
		}
		else if(OverrideAir.os == OverrideAir.IOS && PermissionCheck.check(PermissionCheck.SOURCE_LOCATION_WHEN_IN_USE) == PermissionCheck.PERMISSION_GRANTED)
		{
			onLocationRequestResult(PermissionCheck.PERMISSION_GRANTED);
		}
		else
		{
			if(OverrideAir.os == OverrideAir.ANDROID)
			{
				PermissionCheck.request(PermissionCheck.SOURCE_LOCATION, onLocationRequestResult);
			}
			else if(OverrideAir.os == OverrideAir.IOS)
			{
				PermissionCheck.request(PermissionCheck.SOURCE_LOCATION_WHEN_IN_USE, onLocationRequestResult);
			}
		}
	}
	
	function onLocationRequestResult($obj:Object):void
	{
		if($obj.state != PermissionCheck.PERMISSION_GRANTED)
		{
			trace("AR ANE needs Location access to work properly");
			return;
		}
		
		trace("Cheers, All permissions are allowed for AR to work correctly.");
		
		goWithARNow();
	}
}