In watch OS 1, I was able to create an instance of a custom view in WatchExtension. I'm not talking about showing it, I mean just creating an instance of the view and then create an UIImage
with its content.
Now, in watch OS 2, I can't access to the UIView
from WatchExtension, even when I have imported the UIKit
framework.
Is there any way to be able to create an instance of UIView
from WatchExtension?
The WatchKit framework provides infrastructure for creating watchOS apps, including an extension delegate that manages background tasks, extended runtime sessions, and Siri intents. The framework also performs other support tasks, such as accessing information about the user's Apple Watch.
WatchKit extension. An extension that contains your watchOS app's code. In Xcode 14 and later, you can produce watchOS apps with a single watchOS app target for code, assets, extensions, and localizations. These single-target watchOS apps can run on watchOS 7 and later.
To build a watch-only app, start a new project in Xcode, select the Watch App template, and click Next. Provide a name, and choose the interface, life cycle, and language for your watch app. Select the options to include a notification scene template or unit and user interface tests, and click Next.
It seems it's not possible on watchOS2 unfortunately. While watchOS1 used the iOS platform SDK, watchOS2 is a separate platform.
migration docs:
In watchOS 2, you can share code, but not frameworks, between your iOS app and Watch app. Because the apps run on separate platforms with different architectures...
Also in WatchKit in depth 1 wwdc video they mention this:
The WatchKit extension for watchOS 1 is something you have created already, there is a target in your project, but it uses the iOS platform in SDK.
Here are the available system technologies you can use on watchOS2.
I did the same thing on watchOS1 like you, used a UIView and snapshotted it into a UIView. Besides doing this on the phone and sending it back to the watch (in which you loose the benefit of watchOS2 that the extension runs on the watch and doesn't need to communicate with the phone), or getting it as an image from a server, I don't see any other way of doing it.
edit: there is Core Graphics available so we are able to do basic drawings. See here: http://develop.watch/develop-for-watchos-2-iii-drawing/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With