WatchOS9 - Widgetkit complications do not appear on simulator

Hi,

I followed excactly the steps in https://developer.apple.com/videos/play/wwdc2022/10050 to add Widgetkit for watchOS to my existing iOS Widgets.

Both widgets do work for iOS, but on my Apple Watch, my widget is invisible to be set as a complication.

Any idea what I'm doing wrong?

...

@available(iOSApplicationExtension 16.0, *)
struct MyWidget: Widget {
 private let kind: String = "MyWidget"
  
 var body: some WidgetConfiguration {
  return IntentConfiguration(kind: kind, intent: WidgetConfigurationIntent.self, provider: Provider()) { entry in
   MyWidgetComponent(entry: entry)
  }
  .configurationDisplayName("widget_name_description".localized())
  .description("widget_name_description".localized())
  .supportedFamilies([.accessoryCircular, .accessoryRectangular, .accessoryInline])
 }
}

@main
struct MyAppWidgets: WidgetBundle {
 #if os(watchOS)
 var body: some Widget {
  return MyWidget()
 }
 #else
 var body: some Widget {
  if #available(iOS 16.0, *) {
   return WidgetBundleBuilder.buildBlock(OtherIosWidget(), MyWidget())
  } else {
   return OtherIosWidget()
  }
 }
 #endif
}

...

I get the same issues, see here.

They sometimes work on the Simulator, but most of the time they don't. And they're not working properly at all on a physical Watch.

Apple's videos rarely give you all the info required :(

Take a look at this post. The big green image shows my project structure.

I have my complications in a separate target which the Watch App embeds:

  • Main App (embeds Widget, Widget Intents Handler and Watch App)
  • Widget
  • Widget Intents Handler
  • Watch App (embeds Complications and Complications Intents Handler)
  • Complications (new, copy of Widget, but altered to target watchOS)
  • Complications Intents Handler

If you look in your list of targets (click the blue project icon at the top of the project list), the icon on the Complications one needs to be a circle because it's being deployed to the Watch. Mine didn't work when the icon was a square, because it was inadvertently being targeted to iOS. Go to the Build Settings tab for the Complications target and make sure the Base SDK is watchOS.

When you change anything in the project structure, Xcode gets a bit angry and will gift you a ton of errors. I'd backup your existing project and work on a copy. Let me know how you get on.

WatchOS9 - Widgetkit complications do not appear on simulator
 
 
Q