简体   繁体   中英

Getting images in WatchKit app from iOS app

I'd like to show in a WatchKit app the user's avatar image from its paired iOS app. Such image is downloaded by the iOS app querying a REST web service when the user logs in the app. How could I get it from the WatchKit app?

The downloaded avatar is persisted as a .jpeg file in the Documents folder of the iOS app.

The easiest way to solve your issue is to write the avatar image out to the App Group directory instead of the Documents directory in the iOS app. Then you can load the avatar image from the App Group file system directly from the Watch Extension. In order to do this, you'll need to make the following changes.

Step by Step

  • Add an App Group to your iOS app and Watch Extension
  • Write the avatar image to the App Group instead of the Documents directory
  • Read the avatar image out of the App Group in the Watch Extension
  • Push the avatar image into the WKInterfaceDevice shared image cache
  • Apply the image to either a WKInterfaceImage or WKInterfaceGroup to be displayed

Hopefully that helps make things a bit more clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM