Reputation: 1936
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?
Upvotes: 5
Views: 2337
Reputation: 147
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/
Upvotes: 3
Reputation: 10961
No. In watch OS 2 you cannot dynamically allocate any UI element. You must use storyboard if you want to init any UI stuff.
You create interface objects indirectly by adding the object to your storyboard scene and referring to it from your interface controller. After adding an element to your storyboard, create an outlet for it in your interface controller. During the initialization of your interface controller, WatchKit creates the interface objects for all of your connected outlets automatically. You never create the interface objects yourself.
Upvotes: 2