Skip to main content

Sign in to Aptoide Services (Unity SDK)

Signing in to Aptoide Services links the user's purchases to their Aptoide account. Once signed in, their pending and non-consumable purchases are retrievable via QueryPurchasesAsync even after the host app's storage is cleared or the user switches devices - no backend is required on your side.

📘
Feature availability

Account sign-in is remotely toggled and is off by default. Verify it is available before exposing it with AptoideBillingSDKManager.IsFeatureSupported(3).ResponseCode == 0 (a response code of 0 (OK) means it is enabled; 2 (SERVICE_UNAVAILABLE) means the configuration is still loading - retry).

Sign in

Use AptoideBillingSDKManager.SignInToAptoideServices to launch the Aptoide account sign-in flow. It is asynchronous: the outcome is delivered to the OnSignInResponse method of IAptoideSignInResponseListener as a BillingResult. Call it after the SDK connection is established (for example from a "Sign in" button).

public void SignIn()
{
AptoideBillingSDKManager.SignInToAptoideServices();
}

public void OnSignInResponse(BillingResult billingResult)
{
switch (billingResult.ResponseCode)
{
case 0: // OK
RestoreOwnedPurchases(); // signed in (or already signed in)
break;
case 1: // USER_CANCELED
Debug.Log("Sign-in dismissed by the user");
break;
case -2: // FEATURE_NOT_SUPPORTED
Debug.Log("Sign-in is disabled");
break;
case 2: // SERVICE_UNAVAILABLE
Debug.Log("Not ready yet - retry shortly");
break;
default:
Debug.LogError($"Sign-in error: {billingResult.DebugMessage}");
break;
}
}

The response codes returned to the listener are:

Response codeValueMeaning
OK0The user signed in, or was already signed in. Proceed to query owned purchases.
USER_CANCELED1The user dismissed the sign-in screen or chose "don't show again".
FEATURE_NOT_SUPPORTED-2Account sign-in is disabled (feature flag off).
SERVICE_UNAVAILABLE2The configuration is still loading (or failed to load) - retryable.
ERROR6An unexpected error occurred.

On OK, query the owned purchases to restore the entitlements (the result includes acknowledged non-consumables - see Acknowledge a non-consumable purchase):

private void RestoreOwnedPurchases()
{
QueryPurchasesParams queryPurchasesParams = QueryPurchasesParams.NewBuilder()
.SetProductType("inapp")
.Build();

AptoideBillingSDKManager.QueryPurchasesAsync(queryPurchasesParams);
}

public void OnQueryPurchasesResponse(BillingResult billingResult, Purchase[] purchases)
{
if (billingResult.ResponseCode == 0)
{
foreach (var purchase in purchases)
{
GrantEntitlement(purchase);
}
}
}
📘
Note

The sign-in screen is shown sparingly by the SDK (it is rate-limited and offers the user a "don't show again" option), so calling SignInToAptoideServices is safe - it simply returns without showing the screen when appropriate.

Check the current sign-in state

Use AptoideBillingSDKManager.IsSignedInToAptoideServices to read the current state synchronously - for example, to decide whether to show a "Sign in" or "Log out" button when a screen opens.

bool signedIn = AptoideBillingSDKManager.IsSignedInToAptoideServices();

Listen for sign-in state changes

Sign-in and sign-out can also happen inside the payment WebView. The IAptoideAccountStateListener registered on InitializePlugin is notified of any state change, so you can refresh your UI and re-query purchases without the user restarting the app. The state is 1 when the user is signed in and 0 when signed out. It is only fired on an actual state transition.

public void OnAccountStateChanged(int state)
{
if (state == 1) // SIGNED_IN
{
RestoreOwnedPurchases();
}
else if (state == 0) // SIGNED_OUT
{
RevokeAccountEntitlements();
}
}

Sign out

Use AptoideBillingSDKManager.SignOutFromAptoideServices to sign the user out. It clears the stored session and reverts all subsequent operations to the anonymous guest flow. Any registered IAptoideAccountStateListener is notified with state 0 (signed out).

AptoideBillingSDKManager.SignOutFromAptoideServices();