Skip to main content

Usage

Selecting the Service

As there are multiple services available on Android you will need to specify the service you wish to use by calling initialise() and passing a value defined in the AgeRangeService.

For example to specify the Amazon User Age Verification service:

AgeRange.instance.initialise( AgeRangeService.AMAZON_USER_AGE_VERIFICATION );

You should check if the service is supported on the current device first by calling the isServiceSupported method:

if (AgeRange.instance.isServiceSupported( AgeRangeService.AMAZON_USER_AGE_VERIFICATION ))
{
AgeRange.instance.initialise( AgeRangeService.AMAZON_USER_AGE_VERIFICATION );
}

In this way you can use a service appropriate for the device.

Alternatively you can let the extension select the first available service by using AgeRangeService.DEFAULT:

AgeRange.instance.initialise( AgeRangeService.DEFAULT );

This will select the first available service in the following order on Android:

  • Amazon User Age Verification
  • Google Age Signals

Or for iOS:

  • Apple Declared Age Range
info

This is unused on iOS as there is only one available service there (i.e. Apple's Declared Age Range framework)

If you are solely developing for iOS you can skip the initialise call or you can include it for consistency.

Requesting an Age Range

To request an Age Range firstly construct an AgeRangeRequest object.

This object specifies the details of the request and presents options that vary across the platforms.

For Android there are no options currently however Apple allows you to specify "age gates" or the defined ranges of the request.

As a minimum you should specify the minimum age a user should be to use your application, however you can add two additional levels creating "ranges" for your application.

var minimumAgeForYourApp:int = 18;

var request:AgeRangeRequest = new AgeRangeRequest()
.setAgeGates( minimumAgeForYourApp );

Once you have your request, pass it to the requestAgeRange() method:

AgeRange.instance.requestAgeRange( request );

This will trigger the age request UI and dispatch the result after the user has responded.

Handling the Response

To handle the response you can provide success and failure callbacks to the requestAgeRange() method:

AgeRange.instance.requestAgeRange(
request,
function ( result:AgeRangeResult )
{
trace( "success" );
},
function ( error:Error )
{
trace( "ageRequest ERROR: " + error.message );
}
);

Or alternatively listen for the events dispatched by the AgeRange instance:

AgeRange.instance.addEventListener( AgeRangeEvent.REQUESTAGERANGE_SUCCESS, ageRangeResultHandler );
AgeRange.instance.addEventListener( AgeRangeEvent.REQUESTAGERANGE_ERROR, ageRangeErrorHandler );

function ageRangeResultHandler( event:AgeRangeEvent ):void
{
var result:AgeRangeResult = event.result;
trace( "age request success" );
}

function ageRangeErrorHandler( event:AgeRangeEvent ):void
{
var error:Error = event.error;
trace( "age request ERROR: " + error.message );
}

The AgeRangeResult object returned on success contains information about the user's age range and whether they met the requested age gates.

You can use this information to adapt your application experience accordingly.

Testing

You can force the extension to return a specific result by using the setFakeAgeRangeResult() method.

var fakeResult:AgeRangeResult = new AgeRangeResult()
.setAgeLower( 13 )
.setAgeUpper( 15 )
.setUserStatus( AgeRangeUserStatus.SUPERVISED )
.setInstallId( "FAKE_INSTALL_ID_12345" );

AgeRange.instance.setFakeAgeRangeResult( fakeResult );

Then when you make an age range request the details in this fake result will be returned.

Google Age Signals

On Android we construct a FakeAgeSignalsManager and pass in the parameters from your specified AgeRangeResult (as described in the testing documentation)

Apple and Amazon

With Apple's Declared Age Range and Amazon's User Age Verification services, there is no method in the service to set a test result.

Instead the specified AgeRangeResult will simply be returned in the success callback or event, which means you will not see any UI that would be presented during a normal operation.