iOS WatchOS - what is the difference between WatchKit App and WatchKit App extension?
Asked Answered
D

1

37

I'm trying to create an iOS WatchOS5 complication and am seeing a number of tutorials and apple documentation. They talk about:

  • WatchKit App
  • WatchKit App extension

What is the difference between iOS WatchKit App and WatchKit App Extension?

If I want to share data between my phone app and my watch app, do I need both in order to use Watch Connectivity framework?

Datestamp answered 7/10, 2018 at 11:13 Comment(0)
K
45

Current answer (valid from Xcode 14): the separate 2 targets don't exist anymore, the new default watchOS app template combines the WatchKit App and WatchKit App Extension targets into a single Watch App target, which can store both code and resources, similar to iOS app targets.

See the Xcode 14 release notes (relevant excerpt below).

Xcode 14 includes a new default template for watchOS apps that combines the WatchKit App and WatchKit App Extension targets into a single Watch App target, simplifying code, asset, and localization management. You can deploy single-target watchOS apps to watchOS 7 and later. (83222217)


Historical answer (valid up until Xcode 13): The two come hand-in-hand, both are needed to create a watchOS application and you cannot use one without the other.

The main difference is that a WatchKit App is responsible for displaying the UI, so this is where you store the storyboard(s) and all assets (images, etc) used from storyboards. On the other hand, your WatchKit App Extension is responsible for everything done programatically, so this is where all your interface controllers and other classes should reside. You should also store all assets that you access from code in your App Extension target.

You'll need to use the WatchConnectivity framework from code as part of your App Extension target, however, as already stated, all watchOS applications need to have a WatchKit App target as well.

Kirven answered 10/10, 2018 at 8:43 Comment(6)
I've created new project and all things are in Extension package, in app there is Assets directory and Info.plist. Is it right?Sterilant
@MarekKondracki if you using SwiftUI, that's right, if you are using storyboards, those should go into the app.Kirven
Thanks for the answer. Do you have any information on the reason why there are two targets? Both of them run on the watch, don't they?Truax
@cheesus most probably for historical reasons, since back on watchOS 1, watch apps were not able to execute much logic, pretty much all data had to be sent from the connected iOS app ready to be displayed on the watch. And yes, both targets are executed on the watch.Kirven
It seems like creating a new watch app project (with companion app) nowadays (Xcode 14 beta 5) does not include an extension anymore.Shirleneshirley
@Shirleneshirley thanks for pointing that out, indeed Xcode14 introduced a new watchOS app template, I've updated my answer to reflect this changeKirven

© 2022 - 2024 — McMap. All rights reserved.