How to create a UIView instance from Watch Extension in watch OS 2?

In watch OS 1, I was able to instantiate a custom view in WatchExtension. I'm not talking about this, I mean just creating an instance of the view, and then creating a UIImage with its contents.

Now, in OS 2, I cannot access the UIView from WatchExtension, even when I imported the UIKit framework.

Is it possible to instantiate a UIView from WatchExtension?

+5
source share
2 answers

This seems to be impossible on watchOS2, unfortunately. While watchOS1 used the iOS platform SDK, watchOS2 is a separate platform.

migration documents:

In watchOS 2, you can share code, but not frameworks, between your iOS app and Watch. Because applications 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 what you have already created, there is a goal in your project, but it uses the iOS platform in the SDK .

Here are the available system technologies that you can use on watchOS2.

I did the same on watchOS1 like you, used UIView and took a picture in UIView. Besides doing this on the phone and sending it back to the watch (in which you lose the advantage of watchOS2 that the extension works on the watch and does not need to communicate with the phone) or receiving it as an image from the server, I see no other way to do this.

edit: There is Core Graphics, so we can do basic drawings. See here: http://develop.watch/develop-for-watchos-2-iii-drawing/

+3
source

No. In OS 2, you cannot dynamically highlight any user interface element. You must use the storyboard if you want any user interface material.

Creating an Interface Object

You create interface objects indirectly by adding an object to your scenario scene and referring to it from your interface controller. After adding an item to the storyboard, create an output for your interface controller for it. During the initialization of your interface, the WatchKit controller creates interface objects for all of your automatically connected. You never create interface objects yourself.

+2
source

All Articles