Apple Watch Kit Development Tips

WatchKit Development Tips

Optimize your WatchKit apps with these tips and best practices.

General Guidance

Animate with image sequences.

Animations on Apple Watch are created using sequentially named image resources that the system repeatedly loops. Additionally, you can specify a range of images to animate over a specific duration with a defined repeat count or reverse an animated sequence by setting the duration to a negative value.

Store image sequences on Apple Watch.

Animated sequences should reside on Apple Watch when an animation is started. Add pre-made sequences to your WatchKit app bundle or add an animated UIImage object in the image cache via WKInterfaceDevice to create and store sequences for later use. To reduce load times, create animations that use the fewest images possible while still delivering the desired visual effect.

Use a settings bundle.

Give users control of WatchKit app settings with a settings bundle, similar to iOS. This settings bundle is exposed in the Apple Watch app on iPhone.

Go straight to dictation.

If you are using the text input controller to enable dictation, send people directly to dictation without an intermediary sheet by passing no suggestions and setting the text input mode to plain.

State restoration.

Save the state of your app and its user interface with an interface controller’s didDeactivate: method. Then restore your app and its user interface to its previous state usingwillActivate: in the root controller.


Minimize traffic.

A well-performing WatchKit app requires minimal traffic between iPhone and Apple Watch.

Update only what has changed.

Your WatchKit extension should only update values that have changed instead of reloading values on all properties in a controller. This is particularly important when manipulating table rows. Instead of reloading an entire table, only update, add, or remove what has changed.

Load content lazily.

To optimize the launch time of your WatchKit app and make your app feel more responsive, load the content below the initially visible area of a controller after the controller has displayed to the user. By making a dispatch_async call within the WKInterfaceController willActivate: method, you can delay setting specific content until the controller has been displayed.

Initialize paginated controllers quickly.

To reduce the load time of paginated controllers, complete most of the setup work for each page in the first call to each controller’s willActivate: method and manage state to only setup content the first time it’s called. When paginated controllers are created, init: and awakeWithContext: are called on each page before willActivate: is called on the first page. The system will wait until all pages are finished doing setup work in init: and awakeWithContext: before displaying the first page to the user.

Simplify controller scenes.

Reduce the number of hidden objects as much as possible to significantly improve load time. For example, five versions of a controller’s layout in a single controller scene will result in all objects being created before the controller is displayed.

Improve load times with fewer table rows.

Make sure to create the optimal number of rows to display initially, and delay the loading of additional rows untilwillActivate: is finished. All table rows are created before the controller is displayed, and the more rows that you define, the longer the controller may take to display.

Communicating with iPhone

The iPhone app should do most of the work.

If your app on Apple Watch needs to perform longer running background tasks, such as networking calls, you should rely on your iPhone app to do the work. Use theopenParentApplication:reply: method inWKInterfaceController to wake up your iPhone app in the background and return the data that your WatchKit extension needs. The UIApplicationDelegate method that handles the WatchKit request must return immediately. If an asynchronous call is required, to perform networking for example, use a background task to make sure your app is not suspended before it has a chance to send its reply.

Share data with App Groups.

Easily share small amounts of data between your iOS app and your WatchKit extension with App Groups andNSUserDefaults. For access to other resources, such as a Core Data store, use a shared container between your iOS app and your WatchKit extension to simplify data access and provide up to date information.

Use Handoff.

Handoff lets users easily move between your app on Apple Watch and your app on iPhone. The Handoff API available inWKInterfaceController should be used in your Glance and custom notification interfaces to create deep links into your iPhone app. Use this API to package relevant information about what your interface is currently doing and pass that information to your app’s main interface controller so it can present a different interface upon launch.Learn more about Handoff

Share code with frameworks.

Create a framework to share code between your iOS app and WatchKit extension. Frameworks keep your code accessible, prevent redundancy, and ensure that bug fixes work across multiple instances of code in your project.


About the author