WatchKit Retrieve Multiple URL Images

98 Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

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?