UITableView Prefetching

One day you face a cruel reality: you need to create a lot of In-app purchases (IAPs) on iTunes Connect. You could do that manually, but, obviously, that’s not an optimal way. Why suffer if we can automate this? We’re developers, after all.

You’ve probably heard about fastlane - a great toolset for automating the deployment process for iOS developers. Luckily it also includes spaceship - a Ruby library to access the Apple Developer Center and the iTunes Connect portals. Spaceship also lets us to create/edit/delete IAPs and subscriptions via command line, though this functionality is not properly documented yet.

To start using spaceship, you need to install fastlane first.

Then, type irb in your terminal to launch Interactive Ruby shell and execute require "spaceship".

To log in to iTunes Connect, perform this command:

Spaceship::Tunes.login("user@email.com", "password")

After successful login find your app using bundle id:

app = Spaceship::Tunes::Application.find("com.your.app")

You can even create a new app by using Spaceship::Tunes::Application.create command. See docs for more info.

This command lists all In-app purchases for your app:

app.in_app_purchases.all

To create a non-consumable IAP:

app.in_app_purchases.create!(
type: Spaceship::Tunes::IAPType::NONCONSUMABLE, 
versions: {
  "en-US" => {
    name: "Display name",
    description: "Description has at least 10 characters"
  }
},
reference_name: "IAP reference name",
product_id: "com.your.app.consumable",
cleared_for_sale: true,
review_notes: "A note for a reviewer",
review_screenshot: "/Users/you/Desktop/iap.jpg", 
pricing_intervals: 
  [
    {
      country: "WW",
      begin_date: nil,
      end_date: nil,
      tier: 1
    }
  ] 
)

This code creates 10 consumable IAPs with different tiers, starting from Tier 1:

10.times do |n|
  i = n + 1
  puts i;
  app.in_app_purchases.create!(
    type: Spaceship::Tunes::IAPType::CONSUMABLE, 
    versions: {
      "en-US" => {
        name: "Tier #{i}",
        description: "Description for Tier #{i}"
      }
    },
    reference_name: "Tier #{i}",
    product_id: "com.your.app.#{i}",
    cleared_for_sale: true,
    review_screenshot: "/Users/you/Desktop/iap.jpg", 
    pricing_intervals: 
      [
        {
          country: "WW",
          begin_date: nil,
          end_date: nil,
          tier: i
        }
      ] 
  )
end

As of now, this feature isn’t documented in fastlane/spaceship docs. For more information of using this API check out this pull request: https://github.com/fastlane/fastlane/pull/7834. It also has examples how to create in-app subscriptions programmatically.

Hope this will help you to increase your producivity! 👍