Pete
Pete

Reputation: 219

Xcode Widget Extension Cannot Preview in WatchOS

I am adding a Widget Extension (named Complication) to my WatchOS app. When creating the widget, I am not able to select an application in the field "Embed in Application". The app name shows up, but I can only select "None".

When I want to preview the widget, the following error message comes up:

AppExtensionNeedsContainingAppError: ComplicationExtension.appex must be in an app

The app extension "ComplicationExtension.appex" needs to be embedded in an app in order to use previews

What can I do to get it to work? I added the app in the Target Membership but that does not work. What am I missing?

Upvotes: 4

Views: 851

Answers (3)

Shourob Datta
Shourob Datta

Reputation: 2092

The problem is you are using widgetkit(WidgetKit) needs to attach to an application.

  • Go to Target and select your watchOS application.
  • GO to the Build Phase tab.
  • Go to the section Target Dependency.
  • Add your widgetKit extension on the Target Dependency.

Upvotes: 0

Sn0wfreeze
Sn0wfreeze

Reputation: 2031

You will need to follow the answer here: https://stackoverflow.com/a/76467859/1203713

  1. Add the watchOS Widget Extension
  2. Make sure the extension is embedded in the watchOS App and not in the WatchKit Extension
  3. Make sure the bundle identifier does not contain .watchkitapp.watchkitextension

Then it worked fine for me

Upvotes: 0

arpi17
arpi17

Reputation: 51

I was having the same issue first in my project (Watch only app). I figured that after selecting File > New > Target I also had to select WatchOS on the top before clicking "Widget Extension" otherwise I ran into the same problem (by default it added an iOS widget extension). With the right platform selected I was able to choose which app to embed the widget in and the preview worked correctly

Upvotes: 0

Related Questions