Ensure that your watchOS content is relevant and up to date.
A watchOS app rarely runs in isolation; it needs data from the outside world. You can access data directly from a web service or other online resource, or share data from a paired iPhone.
Access Data Directly
Your watchOS app can connect directly to web services and other online sources. When making these requests, the system can send data through a paired iPhone as a proxy, over a known WiFi network, or over the watch’s own cellular connection (see Testing watchOS Networking).
Always use a
URLSession object to make network requests; however, the type of session varies depending on your app’s needs:
If your app is running in the foreground, use a default or ephemeral session to avoid any delays to your request.
If your app is running in the background (or about to become inactive), use a background session to ensure the request completes.
Default and ephemeral sessions minimize any possible delays between making the request and receiving the response. These sessions are ideal for small exchanges of data as the user is actively interacting with the app. You can also use them to update your app’s content whenever the app becomes active. For more information, see Making Default and Ephemeral Requests.
Background sessions, on the other hand, guarantee that your app eventually receives a response, even if your app becomes inactive or terminates. However, background sessions may be delayed or deferred based on available system resources. For more information, see Making Background Requests.
To learn more about using URL sessions, see URL Loading System.
Use CloudKit to Store Data in the Cloud
CloudKit lets you easily save data in an iCloud container, sharing that data across all the user’s iCloud-connected devices. For example, you could use CloudKit to share your app’s settings or sync the user’s current location in a long-form audio file. CloudKit also lets you create cloud-based apps without having to set up and manage your own servers.
For more information, see CloudKit.
Share Data with the Paired iPhone
While your watchOS app can schedule periodic background tasks to update its information, these tasks are strictly limited—both in the number of times your app can wake per day, and in the amount of time it is allowed to run when it wakes. Additionally, your app is not guaranteed to receive this background execution time. Apps with a complication in the active watch face, and apps in the dock (as shown in Figure 1 and Figure 2) are given priority over other apps.
iOS apps have more flexibility when it comes to scheduling and running in the background. You can take advantage of this flexibility to update your watchOS app from the companion iOS app. For example, whenever the user’s iPhone and Apple Watch can communicate with each other, use the WatchConnectivity framework to opportunistically send updates from iOS to watchOS.
However, with the release of the Watch Series 3 (GPS + Cellular), the watch is likely to be away from its paired iPhone for longer periods. It is important that your app continues to provide useful information, even when it can’t connect with the paired iPhone. This means you can’t rely on WatchConnectivity as your only means of updating the watchOS app. Instead, use the WatchConnectivity framework as an opportunistic optimization, rather than the primary means of supplying fresh data.
For more information on using background refresh tasks, see
For more information on using the WatchConnectivity framework, see Communicating with the Counterpart App.
Test Your Update Code with Different Configurations
When your watchOS app makes a URL session request, the system can route the request three different ways:
Proxy through iPhone
Connecting to a known network
Connecting using cellular data
Proxy through a paired iPhone. If the watch can communicate with a paired iPhone, the request is proxied through the phone and uses the phone’s connection. When connected to a paired iPhone, the control center shows a green iPhone icon in the upper-left corner.
Connect to a known network. If the watch cannot connect to a paired iPhone, but it can connect to a known WiFi network (a network that the user has previously logged into with their phone), then the request is sent using the WiFi network. When connected to a known network, the control center shows the WiFi network in the upper-left corner.
Connect using cellular data. If the watch cannot connect to either a paired iPhone or a known WiFi network, the request is sent using its cellular connection—Apple Watch Series 3 (GPS + Cellular) only. When using a cellular connection, the control center shows the cell connection’s signal strength as green dots in the upper-left corner.