2017-02-10 15 views
11

내가 그 방법을 구현 한 후 WCSession 방법 sendMessage:replyHandler:errorHandler:는 WCErrorCodeDeliveryFailed :</p> <p>WCSession _onqueue_notifyOfMessageError : 페이로드가

를 사용하여 아이폰과 애플 시계 사이에 데이터를 공유, 나는 같은 오류가 응용 프로그램에서 일하고 있어요 배달 할 수없는 : withErrorHandler : errorHandler : 예 (WCErrorCodeDeliveryFailed)입니다.

Error = 페이로드를 전달할 수 없습니다.

import Foundation 
import WatchKit 
import WatchConnectivity 

class ResultInterfaceController: WKInterfaceController, WCSessionDelegate { 

override func awake(withContext context: Any?) { 
    super.awake(withContext: context) 

    let applicationData = ["name": "ViratKohli"] 
    self.sendToPhone(data: applicationData) 
} 

func sendToPhone(data: [String: Any]) { 

    if WCSession.isSupported() { 

     let session = WCSession.default 
     session().delegate = self 
     session().activate() 

     if WCSession.default().isReachable { 

      session().sendMessage(data, replyHandler: {(_ replyMessage: [String: Any]) -> Void in 

       print("ReplyHandler called = \(replyMessage)") 
       WKInterfaceDevice.current().play(WKHapticType.notification) 
      }, 
      errorHandler: {(_ error: Error) -> Void in 

       print("Error = \(error.localizedDescription)") 
      }) 
     } 
    } 
} 
.... 

도움을 주시면 감사하겠습니다.

+0

[this] (http://stackoverflow.com/questions/33200630/wcsession-sendmessagereplyhandler-error-code-7014-wrocrorcodedeliveryfailed) 도움이 될까요? –

+0

@ ReinhardMänner nope. 그게 아니라 – SahyadriChava

답변

5
  1. ios 측의 WCSessionDelegate에 session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void)이 있습니까?
  2. 이 메서드 내부에서 replyHandler()을 호출합니까?

session(_ session: WCSession, didReceiveMessage message: [String : Any])은 replyHandler없이 보낸 메시지에만 호출됩니다.

+0

정답입니다. 'replyHandler'가 제공되었지만 다른 앱이'replyHandler'와 함께 변형을 구현하지 않으면, 요청은 실패합니다. –