1

I am creating a conversation thread using WatchKit 2.0 and am having difficulty downloading multiple images within a conversation. I am able to get a single image using the WatchConnectivity sendMessage. I can get back NSData which I can use for the UIImage.

When there was two different images in the conversation thread, neither of those calls retrieve the image properly. The code I use to fire off the message is

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)
    })
}

I attempted using another thread with

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0))

But that didn't help either. I found a post Load image from URL on WatchKit, but the NSURLSession never completed, even with only one image.

How can I retrieve multiple images from different URLs?

Community
  • 1
  • 1
Mike Walker
  • 2,944
  • 8
  • 30
  • 62

1 Answers1

0

Are you requesting both images from the same sendMessage call? There is a size limit for how large the NSData object can be, and it's only a few megabytes. You might want to try to break the requests to retrieve the images into two separate calls.

Also, is there any error message printed from your error handler?

lehn0058
  • 19,977
  • 15
  • 69
  • 109
  • I did have to use separate calls for each image. And since there is a size limit, I did revert to using the message on the link I included. Also had to make sure the `NSAllowsArbitratyLoads` boolean in the `info.plist` was set. – Mike Walker Feb 12 '16 at 19:13