How In App Purchas work?

Just to clarify. How does the In App purchase work from the technical side. I submit my App with all the content inside even the unlockable stuff. But how should I make it possible that the person which bought the contentpack gets feature unlocked. Should I make a function which saves (after successful purchase) a variable like

var contentpack1 : boolean = false; //default is false

If (purchchase_successful == true){

contentpack1 = true;
//than save this var in a file
}

and at every app start just call a function like:

function Awake(){

if (contentpack1 == true){
show_contentpack1();
}
else{
//do nothing an keep the contentpack locked
}

}

You do submit your app without unlockable stuff, it must be uploaded somewhere on the internet. When user purchases the unlockables, you just download them from the internet and save on device. And every time when the app opens just check if the content is in phone. If it isn’t you just can’t load it.

For app purchases I recommend you to use AssetBundles, but if you haven’t got iPhone Pro, you can write loader system by yourself if the unlockable content depends on the same scripts as your regular game.

Thank you for your response :slight_smile:
But is this really the only way to handle the content? Where should I upload my content packs? At my private webspace?

How to handle if I want to offer a purchase so that my app gets Ad-free? For such a thing I don’t really need to download something. I would just deactivate the banner and that’s it. How to handle something like that?

Did anyone with the Unity-Basic version coded a loader system for downloaded content?

Your content packs should be uploaded to your website.
Pseudo-code for ad-free version:

if(!PlayerPrefs.GetString("Ad-Free")){
ShowAds();
}
if(buyWasSuccesful){
PlayerPrefs.SetString("AddFree","unlocked")
}

Can you post what type of game your’e working on? I may help you on writing level loader system

Actually you can do it anyway you like, sell in-game currency for instance doesn’t require a download.

There are 3 types of in-app items:

  1. Consumables (lives, coins, power ups etc)
  2. Non-Consumables (new levels, new skins etc)
  3. Subscriptions (access to online features maybe)

The 3rd kind you do have to have your own server to keep track of content but the first 2 you can do it without a server.

What Apple want you to do with in-app purchases is follow these steps:

  1. Initialise the storekit by sending the app-store a list of possible item-IDs (com.company.game.item1, etc)
  2. Wait for the call back for all valid IDs (set in itunes connect)
  3. Display the item’s name, description, local currency and price of each item you want to have available. This information must be from the app-store and not hard coded so that it reflects changes in app-store prices or local currency.

Next you send the purchase request along with the item ID and quantity if it’s consumable.

If it’s non-consumable you can request a purchase history and it wont cost a thing if they’ve already bought it and moved to another device.

You wait for the response containing the item ID and/or error code if there were any errors (you’ll find the error codes are really not helpful anyway)

You can then use the returned item ID from the call back to unlock whatever feature you programed.

One final caveat; if the user starts a transaction but then gets a call or exits the game before the response, the next time you log into the app-store from the game you must be ready to handle the call back for any completed transactions.

Also if you want to prevent people simply editing their save files to unlock stuff you can encrypt the saved key to make it harder or check every time with the app store for purchase history. The latter is not recommended at start up because the game will ask for the user’s app store password every time they play.

There is an example md5 encryption method and script in the unity wiki you can use.

You can buy what you want to open, it is entirely up to you. When the acquisition is completed, you can only save the value of NSUserDefaults, and read again to check if the desired function is open.

So is it possible to add extra levels as DLC with iPhone basic? I was told you need to use asset bundles, which isn’t available. How else would you do it?