Unable to load LCR image in tvOS apps
Ok I kind of found the work around myself for this problem. So I am posting here if in case anyone else is facing same problem. Below is code with explanation:
if let url = NSURL(string: "https://.lcr-file-url") {
if let data = NSData(contentsOfURL: url){
let documents = NSURL(string: NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0])
let writePath = documents!.URLByAppendingPathComponent("file.lcr")
data.writeToFile(writePath.absoluteString, atomically: true)
let image = UIImage(contentsOfFile: writePath.absoluteString)
}
}
Basically we need to download the image data and save it in some local file and use contentsOfFile method to have actual image.
If anyone else know better solution than this, I would be happy to hear :)
Creating a UIImage from a remote LSR file
That's how i solved it:
- Convert you .lsr file to a .lcr file doing this from console:
xcrun --sdk appletvos layerutil --c your_file.lsr
- Upload your_file.lcr on your server
Put these two functions into an util class:
func getDataFromUrl(url:NSURL, completion: ((data: NSData?, response: NSURLResponse?, error: NSError? ) -> Void)) {
NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) in
completion(data: data, response: response, error: error)
}.resume()
}
func downloadImage(url: NSURL, imageView: UIImageView){
print("Started downloading \"\(url.URLByDeletingPathExtension!.lastPathComponent!)\".")
getDataFromUrl(url) { (data, response, error) in
dispatch_async(dispatch_get_main_queue()) { () -> Void in
guard let data = data where error == nil else { return }
print("Finished downloading \"\(url.URLByDeletingPathExtension!.lastPathComponent!)\".")
imageView.image = UIImage(data: data)
}
}
}Use it like this:
if let checkedUrl = NSURL(string: "http://domain/path/to/your_file.lcr") {
self.my_ui_view.contentMode = .ScaleAspectFit
downloadImage(checkedUrl, imageView: self.my_ui_view.contentMode)
}
This will use the image without saving it into the document directory, if you need that solution, ask me and i'll share.
How to create a tvOS icon without Photoshop
You don't need to deal with .lsr file at all. You just need to have separate PNG file for each layer, and construct the "App Icon - Small" with them in the asset file. Xcode even gives you a nice Parallax preview.
Therefore, you don't need to use PhotoShop at all. Any app that can deal with PNG files (even the Preview app of OSX) is sufficient.
Related Topics
How to Remove Items from an Array When Deselecting a Row in a UItableview
How to Insert UIlabel After UItextfield in UIalertcontroller
Adding Data to a Specific UId in Firebase
Indent Second Line of UIlabel (Swift)
Spacing Between Sections in a Form
Realm Data Insertion Took Over 7Mins for Big Size JSON
Moving from Nsurlconnection to Nsurlsession for Soap Post in Swift
Midiclientcreate Does Not Work for 32 Bit Processors in Swift
How to Pull The Artist Value from Mpmediaitemcollection
Swift 3 Cocoa: Use Quicklook to Preview File in Os X
iOS Charts - Single Values Not Showing Swift
How to Drag a Working Slider Using Swiftui
Place Multiple Scn Objects in Touchesbegan Method
Can't Update Label from Other Class in Swift
How to Create a UIprintpaper to Test UIprintinteractioncontrollerdelegate