1
iOSからwatchOSに画像を送信しようとしましたが、以下のエラーが発生しています。 InterfaceControllerクラスでWCSession sendMessageDataがwatchOS 3で動作しません
のViewControllerクラスでsendMessageData getting error: Error Domain=WCErrorDomain Code=7014 "Payload could not be delivered." UserInfo={NSLocalizedDescription=Payload could not be delivered.
私のコード
var session: WCSession?
override func viewDidLoad() {
super.viewDidLoad()
session?.delegate = self
if (WCSession.isSupported()) {
session = WCSession.default()
session?.delegate = self
session?.activate()
}
}
let image = UIImage(named: "img1")!
let data = UIImagePNGRepresentation(image)
session?.sendMessageData(data!, replyHandler: { (data) in
print(data)
}) { (error) in
print(error)}
}
override func willActivate() {
super.willActivate()
if (WCSession.isSupported()) {
session = WCSession.default()
session.delegate = self
session.activate()
}
}
func session(_ session: WCSession, didReceiveMessageData messageData: Data) {
guard let image = UIImage(data: messageData) else {
return
}
print(image)
}
おかげで、