WatchKit 检索多个 URL 图像

WatchKit Retrieve Multiple URL Images

我正在使用 WatchKit 2.0 创建对话线程,但在下载对话中的多个图像时遇到困难。我可以使用 WatchConnectivity sendMessage 获取单个图像。我可以取回 NSData,我可以将其用于 UIImage

当对话线程中有两个不同的图像时,这些调用都无法正确检索图像。我用来触发消息的代码是

if WCSession.isSupported() {
    // Set the session to default session singleton
    session = WCSession.defaultSession()
    // Fire the message to iPhone app
    session!.sendMessage(["action": "getImage", "url": message.media.filename], replyHandler: { (response) -> Void in

        // Extract the image data of the boarding pass
        if let data = response["messageData"] as? NSData {
            row.image.setImage(UIImage(data: data))
        }
        , errorHandler: { (error) -> Void in
            // Print error
            print(error)
    })
}

我尝试使用另一个线程

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0))

但这也无济于事。我找到了 post Load image from URL on WatchKit,但是 NSURLSession 从未完成,即使只有一张图片。

如何从不同的 URL 检索多张图片?

您是从同一个 sendMessage 调用请求两个图像吗? NSData 对象的大小是有限制的,只有几兆字节。您可能想尝试将检索图像的请求分成两个单独的调用。

此外,您的错误处理程序是否打印了任何错误消息?