ARTICLES

How to use Content Hosting for In-App Purchase Content

Apple allows apps developers to host their In-App Purchase Content on Apple’s servers.  To set up Content Hosting you will need to use iTunes Connect, Xcode and the Application Loader.  The IAP must be non-consumable to take advantage of content hosting.

iTunes Connect

Go to your app in iTunes Connect, then select Features, In-App Purchases.  Create a new In-App Purchase or select an existing one.  In the Content Hosting section, press “Turn On Content Hosting”.

Source: https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/iTunesConnectInAppPurchase_Guide/Chapters/CreatingInAppPurchaseProducts.html

Xcode

You will need to create a new Xcode project to host your In-App Purchase Content.

In Xcode, go to File -> New -> Project….  Then select the Cross-platform tab and the In-App Purchase Content template.  Set your Product Name and Organization Identifier such that the resulting Bundle Identifier matches the Product ID of the IAP in iTunes Connect.

Add your IAP content to the same folder that contains the ContentInfo.plist file.  When your done adding content files, select: Product -> Archive.  From the Organizer, press Export and select “Export as an Installer Package” to create a .pkg file.

Don’t bother validating the project.  If you do you’ll just get the error “An error occurred. Archive item is not associated with any known iTunes Connect platform.”  This is because you need to use the Application Loader and not Xcode Organizer.

In your main iOS app project you’ll have to implement SKPaymentQueue start, cancel, pause, and resumeDownloads functions.  Each of these takes an array of SKDownload objects.  You’ll also want to implement the SKPaymentTransactionObserver func paymentQueue(SKPaymentQueue, updatedDownloads: [SKDownload])

Note that while the hosted content is downloaded as a zip file you do not need to unzip it.  The files are in the Contents directory.  You can use the sample code below to iterate through the contents directory.  You’ll need to copy the files over to your Application Support Path.  You’ll also need to exclude the files from iCloud backup.  Finally, you can delete the zip file from the cache directory.

func procesessDownload(download: SKDownload) {
    guard let hostedContentPath = download.contentURL?.appendingPathComponent("Contents") else {
        return
    }

    do {
        let files = try FileManager.default.contentsOfDirectory(atPath: hostedContentPath.relativePath)
        for file in files {
            let source = hostedContentPath.appendingPathComponent(file)
            //copy to Application Support Path and mark as exclude from iCloud backup
        }

        //Delete cached file
        do {
            try FileManager.default.removeItem(at: download.contentURL!)
        } catch {
            //catch error
        }
    } catch {
        //catch error
    }
}

 

Application Loader

You’ll need to upload your IAP .pkg content file via the Application Loader program.  If it is your fist time using the Application Loader you’ll need to sign in with your iTunes username and an app specific password. You can create an App Specific Password at https://appleid.apple.com/#!&page=signin and select “Generate Password…”.  If you’ve used Application Loader in the past but haven’t updated it to use an App Specific password you’ll have to sign out and sign back in with the new password.

Select the New In-App purchases template, then Choose.  Now select the corresponding App and press Manage.  Select the IAP you would like to upload the content to.  Update the Name and Review Notes if necessary and select Next until you get to the “Hosted Content” tab.  Press Choose and select the .pkg file from earlier.

Press Next and save the .itmsp file to disk and press Deliver to upload the file to Apple’s servers.

If you get the following error: ERROR-ITMS-2000 “Version x, Locale ”xx-xx’: keywords cannot be edited in the current state” at Software/SoftwareMetadata/SoftwareVersion you’ll have to manually edit your .itmsp file to remove the metadata of the previous version.  See the following Stack Overflow post on the workaround https://stackoverflow.com/a/39246362/1431520

Testing

To test your In-App Purchases in development mode on your test devices you will have to set up a sandbox user in iTunes Connect.  Follow the instructions under “Sandbox Testers” located at https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/Chapters/SettingUpUserAccounts.html.  When beta testers receive your app via Test Flight they can make In-App Purchases for free using their regular iTunes account.

 

To link your In-App Purchases with installs generated via Apple Search Ads check out Kitemetrics by Kitefaster.  Kitemetrics helps you optimize your bids and keywords to increase revenue.



Our Products

Kitemetrics
Keyword level attribution for Apple Search Ads. Optimize your bids and increase your revenue. Sign up for free at kitemetrics.com.

White Noise and Deep Sleep Sounds
Calming and relaxing sounds that will help you sleep like a baby tonight.
Download for free from the App Store.
Get it on Google Play.




Our Sponsors

Get Sleepy
Get Sleepy
The free podcast that puts you to sleep with meditative bedtime stories. Listen at getsleepy.com.