When switching apps between paid/free for promo periods it’s obviously possible to switch ads on/off externally, but doing that, there’s always going to be a few users who end up paying but still seeing ads, or getting the app for free without seeing them… So I’d like to handle it in-game.
So, how can my app tell whether it was downloaded for free or paid for? I’ve found several devs alluding to this on blog posts stec. but I can’t find any info on how it’s done. I’ve looked through the Prime31 plugins, been through the docs, and Googled this but I can’t find any info at all.
This works by looking for the app receipt and the build number in it (not the version).
I changed the build number of my free versions. Anything with build 1 was paid, anything with build 111, 112, etc is free. Then I check the receipt of the app and if I find one (not always the case) I can see the build number and act accordingly. Note that when you are testing this you will always get build number 1.0.
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
// Get a reference to IAppleConfiguration during IAP initialization.
var appleConfig = builder.Configure<IAppleConfiguration>();
var receiptData = System.Convert.FromBase64String(appleConfig.appReceipt);
AppleReceipt receipt = new AppleValidator(AppleTangle.Data()).Validate(receiptData);
//there are older builds 20 etc, version 2
//check characters
// we will take a conservative approach
// if we see the build is 11, then we ask for paywall
// if there is no receipt or if the original build is different we will not show paywall
if (receipt == null) //no receipt
{
/// we just assumed
EnablePayWall = false;
Debug.Log("No receipt");
} else
{
//testing -> 1.0
//production -> 11
string FreeBuild = "11";
string OriginalBuild = receipt.originalApplicationVersion;
if (OriginalBuild.StartsWith(FreeBuild))
{
EnablePayWall = true;
Debug.Log("app was free");
} else EnablePayWall = false;
//Debug.Log("receipt bundle: " + receipt.bundleID);
//Debug.Log("receipt creation date: " + receipt.receiptCreationDate);
//Debug.Log("receipt build: " + receipt.originalApplicationVersion);
}