Skip to main content

Usage

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.

Android

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

iOS

On iOS, there is no method in the Declared Age Range framework 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.