2016-11-22 82 views

回答

0

它沒有framwork,但我已經寫了這個擴展:

extension WKInterfaceImage { 
    public func imageFromUrl(_ urlString: String) { 

     if let url = NSURL(string: urlString) { 

      let request = NSURLRequest(url: url as URL) 
      let config = URLSessionConfiguration.default 
      let session = URLSession(configuration: config) 

      let task = session.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in 
       if let imageData = data as Data? { 
        DispatchQueue.main.async { 
         self.setImageData(imageData) 
        } 
       } 
      }); 

      task.resume() 
     } 
    } 
} 

一個WKInterfaceImage只需添加到您的watchOS故事板,將其固定,然後調用 imageView.imageFromUrl("https://something")

讓我知道,如果它的工作原理!