Reputation: 509
I need to use some images in my WatchOS app and its complications. If I put them in the assets catalog inside the watchkit app target group I can't access them from my WatchOS app, but in the extention assets catalog I can.
This is how I tested the accessibility:
CircularSmallRingImage42mm
from Attribute Inspector. I added the following code in the awakeWithContext()
method in my initial InterfaceController
:
if let image = UIImage(named: "CircularSmallRingImage42mm") {
NSLog("works")
} else {
NSLog("doesn't work")
}
I reset content and settings on the Apple Watch Simulator.
The assets catalog in my watchkit app group is targeted only on watchkit app. The assets catalog in my watchkit app extension group is targeted only on watchkit app extension. Everywhere I look people seem to recommend putting static content into an asset catalog bundled with the Watch App target so it gets stored on the watch itself.
Why can't I access the image? Am I doing something wrong? Is the watchkit app bundle not the recommended place for storing static files?
Upvotes: 1
Views: 1351
Reputation: 42
The Assets for iphone app and for watch app is totally different you can't access the images into app asset folder to watch extension. You have to add new images which compatible with the watch kit
Upvotes: 0
Reputation:
Based on the name of the image, it sounds like it's related to a complication.
Complication images belong in the WatchKit Extension Asset Catalog, since the complication is an "extension" of your app. Your app doesn't have to be loaded or running for the complication to function.
You also need to refer to complication images by their group name if they're stored in the Complication group. E.g.,
UIImage(named: "Complication/Circular")
For more details, see this thread at the Apple Developer forum.
Upvotes: 3