Reputation: 123
I am trying to use this solution: load-image-from-url-on-watchkit
I have a table on the watch that I am trying to load images for in each row. I am running this code and then I update the text fields of the table. Without trying to get the images, all the text loads in correctly.
But when I add this code:
let site = "myurl.com/image.jpeg" //I have copied this and it is an image
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let url:NSURL = NSURL(string:site)!
var data:NSData = NSData(contentsOfURL: url)!
var placeholder = UIImage(data: data)!
dispatch_async(dispatch_get_main_queue()) {
row.myRowImage.setImage(placeholder)
}
}
I get the error: fatal error: unexpectedly found nil while unwrapping an Optional value
And I cannot seem to figure out what would cause this if it is a valid url and other parts of the table have loaded correctly. Any help is greatly appreciated!
Upvotes: 4
Views: 1291
Reputation: 3503
The URL string need to conform to URL format as described in RFC 2396 . Basically, you need to have http:// or ftp, etc. at the beginning of your URL string.
Upvotes: 2
Reputation: 99
You are going to want to change the settings in your plist for the app transport security. Do this in watch extension plist if you are doing the network call on the watch. Here is a helpful link
Also for your url you are going to need to use either http:// or https:// in order for this to work.
Upvotes: 3