Ensure that your watchOS app has access to the most recent content available.
A watchOS app rarely runs in isolation. Often 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 it 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 that the request is completed.
Default and ephemeral sessions minimize any possible delays between making the request and receiving the response. These sessions are ideal for any tasks where 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.
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.
On the other hand, iOS apps have more flexibility when it comes to scheduling and running in the background. You can take advantage of this flexibility to also update your watchOS app. Whenever your iPhone app wakes in the background, have it send an update to your watchOS app using the WatchConnectivity framework.
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 its paired iPhone. This means you can’t rely on WatchConnectivity as your only means of updating the watchOS app. Instead, use the WatchConnectivity framework to optimize and streamline your watchOS app.
For more information on using background refresh tasks, see
For more information on using the WatchConnectivity framework, see Communicating with the Counterpart App.