2016-08-01 34 views
0

启动手表的应用程序后,我做的请求,会议以iPhone,但是当我试图返回的图像作为NSData的我得到如何向Apple Watch发送带有文本的图像和阵列?

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.}}, 

对于沟通我用

session.sendMessage(...) 

我应该如何通过图片和文字从iPhone到手表?

+0

你可以看到我的答案http://stackoverflow.com/questions/33113823/how-to-transfer-a-uiimage-using-watch-connectivity在这个问题 –

+0

你试过缩放高分辨率图像,以适应较小的手表屏幕,*之前*将其作为数据传输?这可能有助于图像数据不超过[有效负载限制](http://stackoverflow.com/a/35076706/4151918),并且更节能。 – 2016-08-01 21:01:15

回答

0

您应使用此代码:

PNG图片

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

JPEG图像

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

这段代码是iPhone发送还是Apple Watch? –

0

斯威夫特4版本:

WCSession.default.activate() 
WCSession.default.sendMessageData(UIImagePNGRepresentation(UIImage(named: "imageName.png")!)!, replyHandler: {(_) -> Void in 
       }) {(error) -> Void in 
        print(error.localizedDescription) 
       } 
相关问题