简体   繁体   English

Apple Watch的网址图片

[英]image by url for Apple Watch

I am trying to use this solution: load-image-from-url-on-watchkit 我正在尝试使用此解决方案: 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 我收到错误:致命错误:在展开Optional值时意外发现nil

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. 如果它是一个有效的URL并且表的其他部分已正确加载,我似乎无法弄清楚会导致这种情况的原因。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

You are going to want to change the settings in your plist for the app transport security. 您将要更改plist中的设置以获取应用程序传输安全性。 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. 同样对于您的网址,您将需要使用http://或https://才能使其正常工作。

The URL string need to conform to URL format as described in RFC 2396 . URL字符串需要符合RFC 2396中描述的URL格式。 Basically, you need to have http:// or ftp, etc. at the beginning of your URL string. 基本上,您需要在URL字符串的开头加上http://或ftp等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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