2017-02-10 28 views
11

を配信することができませんでした私は、そのメソッドを実装した後、私のようなエラーが出るWCSession方法sendMessage:replyHandler:errorHandler:はWCErrorCodeDeliveryFailed:ペイロードは

を使用して、iPhoneとAppleウォッチの間でデータを共有するアプリに取り組んでいます:

WCSession _onqueue_notifyOfMessageErrorを:withErrorHandler:errorHandler:WCErrorCodeDeliveryFailedの場合はYESです。

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-werrorcodedeliveryfailed)が役立ちますか? @ReinhardMännernope。 –

+0

それはなかった – 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'を持つバリアントを実装していない場合、リクエストは失敗します。 –

関連する問題