Optimizing your app

After you've finished developing and testing your app, your next step is to get it ready for sale on the App Store. Xcode gives you some opportunities to optimize your app before submission to the store in order to make it fast and easy to download and install on your customer's devices.

App thinning

When you're writing an app for iOS, watchOS, or tvOS, you would want your app to take up as little space on a customer's device as possible. Apple has three technologies that work together under the banner of app thinning in order to make this happen.

Slicing

An Xcode project can include all of the code and resources needed to support many different platforms and devices. Since the app may run on any of these platforms, a developer generally includes all sorts of assets (images, fonts, views, and so on) to make the app look great.

As an example, let's say that you have an app that runs on either an iPhone or an iPad. The app that's installed on an iPhone will never need any of the assets that you have included to support an iPad. Those images and that code simply make your app size bigger. App slicing will remove the iPad resources for you to help save that space. Behind the scenes, Apple will create platform-specific versions of your app and handle their distribution to the appropriate platform for you.

Bytecode

Bytecode is optional, but on by default on iOS, but is mandatory on watchOS and tvOS. Usually, when you submit an app to the App Store, you submit a compiled version of it. With Bytecode, you submit one of the intermediate steps from the source code to the fully compiled app instead. This allows Apple to optimize the compiled binary in future without needing you to resubmit your app.

Starting with the iPhone 5s, Apple started moving their iOS devices from a 32-bit architecture to a 64-bit architecture, and this required every app to be recompiled by each developer in order to gain the benefits of 64 bits. Bytecode would have made it possible for Apple to recompile the apps for 64-bit architecture without any access to the original source code.

On-demand resources

Imagine an interactive encyclopedia app about our solar system for the iPad. It's filled with videos, images, sounds, and animation. Before iOS 9 and Xcode 7, all of those assets most likely needed to be compiled into the app and sent for distribution to Apple. What if a vast majority of the people downloading the app never looked past Mars? This means that the app used a large amount of the limited resources on a device with things that are never seen or heard of.

On-Demand Resources is Apple's attempt to fix this type of issue. In Xcode 7, you can tag various assets (images, sounds, videos, game textures, and particles) together into bundles and then request them to be downloaded from Apple as needed. This lets you shrink down your app to its smallest possible size and fetch things only as they are needed. As we saw earlier in the chapter, this feature requires a full Apple Developer Account.

Assets tagged as on-demand resources need to be able to be deleted and re-downloaded at any time. To help prioritize them, these assets can be categorized as required for the app to run, or they can need to be prefetched to make the app experience better.

There are hard limits on the amount of space that these resources can take up; your app's initial bundle can be 2 GB only, your app can work with only 2 GB of on-demand resources at a time, and Apple will store only 20 GB of assets for you. If you need more space, you can host those resources yourself on any server that can conform to Apple's security requirements.

While Apple has worked hard to make the on-demand resource system not noticeable by your users, there are still some guidelines that they recommend so that there aren't any usability hiccups:

  • Keep your assets as small as possible
  • Download only what you need
  • Download assets as early as possible
  • Mark unnecessary assets for deletion as soon as possible

Keeping the limits and Apple's recommendations in mind will help you minimize the memory usage of your app, keep the network traffic required to run your app at a minimum, and keep your app as small as possible.

It's worth noting that you're required to use on-demand resources with tvOS apps as you're only offered 200 MB of space for your app. Any resources outside of this will need to be downloaded using this system.

On-Demand Resources is an advanced topic with specific use cases; as such, it's not covered in detail in this book. For more information, check out the On-Demand Resources Guide on the Apple Developer site at https://developer.apple.com.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.20