I successfully send messages from iPhone to Watch but I cannot send message from Watch to iPhone. I get the following 7018 error from WCSession.default.sendMessage's error property. There is no question on the Internet with the code. I think this will be related with the latest SDKs.
_onqueue_notifyOfMessageError:messageID:withErrorHandler:] (null) errorHandler: YES with WCErrorDomain:7018
The ouput has also said that iOS app not installed but it also installed beacuse I successfully sending messages from iOS to Watch App.
2019-10-02 15:44:47.598081+0300 WatchAppExample WatchKit Extension[19189:300753] [WC] WCSession iOS app not installed
2019-10-02 15:44:47.598570+0300 WatchAppExample WatchKit Extension[19189:300753] [WC] -[WCSession _onqueue_notifyOfMessageError:messageID:withErrorHandler:] (null) errorHandler: YES with WCErrorDomain:7018
Here's how I send message from Watch to iPhone.
@IBAction func sendiPhoneButtonClicked() {
if WCSession.default.isReachable {
let message = ["message": "Test"]
WCSession.default.sendMessage(message, replyHandler: nil, errorHandler: { (err) in
debugPrint(err)
})
}
}
Here's how I send message from iPhone to Watch
@IBAction func sendWatchButtonClicked(_ sender: UIButton) {
if WCSession.default.isReachable {
let message = ["message": textField.text]
WCSession.default.sendMessage(message, replyHandler: nil, errorHandler: nil)
}
}
Both of ViewController and InterfaceController delegation functions has set.
ViewController.swift
...
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if WCSession.isSupported() {
WCSession.default.delegate = self
WCSession.default.activate()
}
}
...
extension ViewController: WCSessionDelegate {
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
let labelText = message["message"] as? String
debugPrint(labelText)
label.text = labelText
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
debugPrint(error)
}
func sessionDidBecomeInactive(_ session: WCSession) {
}
func sessionDidDeactivate(_ session: WCSession) {
}
}
InterfaceController.swift
...
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
if WCSession.isSupported() {
WCSession.default.delegate = self
WCSession.default.activate()
}
}
...
extension InterfaceController: WCSessionDelegate {
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
let labelString = message["message"] as? String
debugPrint(labelString)
label.setText(labelString)
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
}
}
iOS deployment target: 13.0
WatchApp deployment target: 6.0
Swift 5
Run on iPhone 8 and 11 Pro Max simulators with Apple Watch Series 5 - 40mm