1

After start watch-app I do request session to iPhone, but when I try return Image as NSData i get

Error Domain=WCErrorDomain Code=7011 "Message reply failed." UserInfo={NSUnderlyingError=0x78e9b8d0 {Error Domain=WCErrorDomain Code=7009 "Payload is too large." UserInfo={NSLocalizedRecoverySuggestion=Send smaller payloads., NSLocalizedDescription=Payload is too large.}}, 

For communicate I use

session.sendMessage(...)

And how I should pass image and text from iPhone to Watch?

Asdrubal
  • 2,421
  • 4
  • 29
  • 37
Ivan Vorobei
  • 629
  • 1
  • 6
  • 6
  • You can see my answer http://stackoverflow.com/questions/33113823/how-to-transfer-a-uiimage-using-watch-connectivity in this question – Victor Sigler Aug 01 '16 at 17:35
  • Have you tried scaling the high-resolution image to fit the smaller watch screen, *before* transferring it as data? That would likely help the image data to not exceed [the payload limits](http://stackoverflow.com/a/35076706/4151918), as well as be more energy-efficient. –  Aug 01 '16 at 21:01

2 Answers2

1

You should use this code:

JPEG Image

if WCSession.isSupported(){
    WCSession.defaultSession().activateSession()
    WCSession.defaultSession().sendMessageData(UIImageJPEGRepresentation(UIImage(named: "imageName.jpeg")!)!, replyHandler: {(_) -> Void in
    }) {(error) -> Void in
        print(error.localizedDescription)
    }
}

PNG Image

if WCSession.isSupported(){
    WCSession.defaultSession().activateSession()
    WCSession.defaultSession().sendMessageData(UIImagePNGRepresentation(UIImage(named: "imageName.png")!)!, replyHandler: {(_) -> Void in
    }) {(error) -> Void in
        print(error.localizedDescription)
    }
}
David
  • 87
  • 12
Seyed Parsa Neshaei
  • 3,470
  • 18
  • 30
1

Swift 4 Version:

WCSession.default.activate()
WCSession.default.sendMessageData(UIImagePNGRepresentation(UIImage(named: "imageName.png")!)!, replyHandler: {(_) -> Void in
                }) {(error) -> Void in
                    print(error.localizedDescription)
                }
Alessandro Mattiuzzi
  • 2,309
  • 2
  • 18
  • 24