Search code examples
swiftuiwatchoswidgetkitapple-watch-complicationclockkit

ClockKit and WidgetKit Complications in the same app


I am working on an application for watchOS that needs support from watchOS 7.0 to the last version, in terms of the app itself its going well, but I'm having problems with the complications, I have two sets of working complications, one made with WidgetKit and one with ClockKit, but as they work entirely differently I'm having some trouble connecting the two of them, I want my ClockKit complications to show when the watchOS versions in below 9 and the WidgetKit Complications to show when the watchOS version in 9 or above.

Right now I have three targets that are relevant, a watch target, a watch extension target and a different target for the Complications, because as far as I know you can only set the entry point for the WidgetKit Complications using @main and you can only have one @main per target, so I couldn't have it in the watch extension target in which the rest of my app is, even the ClockKit Complications, as they can be set in the target>Complications Configuration options

In the Info.plist file of my WidgetKit complications target I have the following:

enter image description here

On the NSExtensionPointIdentifier field I change between two values:

com.apple.widgetkit-extension : Whenever I have this value, the app and complications will work fine on watchOS 9+, showing my WidgetKit Complications, however it wouldn't launch on watchOS 9-, saying that "Could not install at this time ... ios.aplicacion.tiempo-com.watchkitapp.watchkitextension.CompliWatchExt specifies a value (com.apple.widgetkit-extension) for the NSExtensionPointIdentifier key in the NSExtension dictionary in its Info.plist that does not correspond to a known extension point." So it doesn't recognize the widgetkit-extension identifier.

com.apple.services : Although I feel this is just any non "widgetkit-extension", because this basically gets rid of the WidgetKit Complications, making it work on any version but only having the ClockKit Complications.

So basically what I want is the app to work as if it had com.apple.widgetkit-extension on watchOS 9+ but to work as it had com.apple.services on watchOS 9-, is there any way to get this result?


Solution

  • Okey I found the solution although it's not really a solution, It was just a misconception from my part, the only thing I needed to do was set the Deployment target to 9.0 in the target I had the Widget Complications in, as Xcode gives preference to the widget kit complications when both are available