WatchConnectivity

RSS for tag

Implement two-way communication between an iOS app and its paired watchOS app using WatchConnectivity.

WatchConnectivity Documentation

Posts under WatchConnectivity tag

61 results found
Sort by:
Post marked as solved
59k Views

[Apple Watch] Unable to Check for Update - Not connected to the internet error

Hi. I am pairing my Apple Watch Series 5 to my iPhone running ios 14. The pairing is successful but unable to proceed with the set up because an update is needed to be downloaded first. I updated the os for watch but I keep on getting “Unable to Check for Update - Checking for a software update failed because you are not connected to the internet”. I am definitely connected to the internet. Watch was reset to factory defaults and I am now pairing it as a new device but it fails due to the issue mentioned above.
Asked Last updated
.
Post not yet marked as solved
1.2k Views

WatchConnectivity not working on device

I have implemented a very simple iOS + WatchOS app project, where I test how one can communicate with the other. I will paste the code below, but the idea is really simple. Each app has one single screen with a button and a label. Tapping the button will send a message to the counterpart indicating the timestamp when the message was generated. If I run the app on the simulators, everything works fine: messages are sent and received correctly on both the iPhone and the Watch. (You can find a reference gif on imgur.com/ + o1ZQTLp). The problem occurs when I try to run the same apps on my physical devices. Session is activated successfully but messages aren't sent. If I debug the code, I even see the WCSession.isReachable value set to true. When debugging the WatchKit app, I see errorHandler is called on the func sendMessage(), and the error states: WatchConnectivity session on paired device is not reachable. However, the errorHandler isn't called from the iPhone app. Details of my devices: iOS version: 14.0.1 WatchOS version: 7.0.1 I tested this same code before installing the 7.0.1 WatchOS and it worked without any problems, so I wonder if the update introduced some error on the WatchConnectivity framework. Code on the iPhone app: import UIKit import WatchConnectivity class ViewController: UIViewController { 		@IBOutlet weak var messageLabel: UILabel! 		fileprivate var wcSession: WCSession! 		override func viewDidLoad() { 				super.viewDidLoad() 				wcSession = WCSession.default 				wcSession.delegate = self 				wcSession.activate() 		} 		@IBAction func sendMessageAction(_ sender: Any) { 				let message = [ 						"content": "Message sent from iPhone on \(Date())." 				] 				wcSession.sendMessage(message, replyHandler: nil, errorHandler: { error in 						print("Error when sending message: \(error.localizedDescription)") 				}) 		} } extension ViewController: WCSessionDelegate { 		func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { 				switch activationState { 				case .activated: 						print("WCSession activated successfully") 				case .inactive: 						print("Unable to activate the WCSession. Error: \(error?.localizedDescription ?? "--")") 				case .notActivated: 						print("Unexpected .notActivated state received after trying to activate the WCSession") 				@unknown default: 						print("Unexpected state received after trying to activate the WCSession") 				} 		} 		func session(_ session: WCSession, didReceiveMessage message: [String : Any]) { 				guard let content = message["content"] as? String else { return } 				DispatchQueue.main.async { 						self.messageLabel.text = content 				} 		} 		func sessionDidBecomeInactive(_ session: WCSession) { 		} 		func sessionDidDeactivate(_ session: WCSession) { 		} } Code on the Watch Kit app: import WatchKit import Foundation import WatchConnectivity class InterfaceController: WKInterfaceController { 		@IBOutlet weak var messageLabel: WKInterfaceLabel! 		fileprivate var wcSession: WCSession! 		override func awake(withContext context: Any?) { 				wcSession = WCSession.default 				wcSession.delegate = self 				wcSession.activate() 		} 		@IBAction func sendMessageAction() { 				let message = [ 						"content": "Message sent from Watch on \(Date())." 				] 				wcSession.sendMessage(message, replyHandler: nil, errorHandler: { error in 						print("Error when sending message: \(error.localizedDescription)") 				}) 		} } extension InterfaceController: WCSessionDelegate { 		func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { 				switch activationState { 				case .activated: 						print("WCSession activated successfully") 				case .inactive: 						print("Unable to activate the WCSession. Error: \(error?.localizedDescription ?? "--")") 				case .notActivated: 						print("Unexpected .notActivated state received after trying to activate the WCSession") 				@unknown default: 						print("Unexpected state received after trying to activate the WCSession") 				} 		} 		func session(_ session: WCSession, didReceiveMessage message: [String: Any]) { 				guard let content = message["content"] as? String else { return } 				messageLabel.setText(content) 		} }
Asked
by matiasb.
Last updated
.
Post not yet marked as solved
44 Views

Sometimes WebSocket connection pending until Screen turns ON

Hi, I'm awaking iOS app from my Watch app and iOS app has to connect my server via Websocket but sometimes this is not working as I expected. In most cases it's working fine but sometimes Websocket connection is kind of pending and I discovered it connects if I turn the screen on of my iPhone. Is this behavior normal? Is it documented because I couldn't see? Thank you!
Asked Last updated
.
Post not yet marked as solved
52 Views

Watch can not receive reply from phone with WatchConnectivity

Test with iphone11(14.6) and watch series3(6.2) In my project, I use WatchConnectivity between phone and watch to communication,  When watch send message with below code, every time run is OK wcSession.sendMessage(message as [String : Any], replyHandler: nil)  But when watch send message need reply, it seems error. wcSession.sendMessage(message) { (reply) in     } errorHandler: { (error) in       } In Phone with below code to deal with request func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {     } func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) { } I debug the code, didReceiveMessage replyHandler can be called, and reply data, but watch can not receive the reply. So what’s my problem, Before the mobile and watch update, everything is good, every update will cause problems, how to ensure the stability of the app?Thank you very much.
Asked
by TimenZhao.
Last updated
.
Post not yet marked as solved
58 Views

Cannot Find "PhoneConnect" in Scope Error

Hi folks, I'm attempting to add WKConnectivity to a SwiftUI app. When I try to introduce the PhoneConnect class to my main view, the error occurred. How can I fix this issue? Here is the code: struct HomeView: View {     @State var Listen = false     @State var showAlert = false     @State var reach = "No"     @ObservedObject var connect = PhoneConnect() //Cannot find 'PhoneConnect' in scope import WatchConnectivity final class MessageViewModel: NSObject, ObservableObject {     @Published var messages: [String] = []     @Published var messagesData: [String] = []          var session: WCSession          init(session: WCSession = .default) {         self.session = session         super.init()         self.session.delegate = self         session.activate()     } } extension MessageViewModel: WCSessionDelegate {     func sessionDidBecomeInactive(_ session: WCSession) {     }          func sessionDidDeactivate(_ session: WCSession) {     }          func session(_ Session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {         if let error = error {             print(error.localizedDescription)         } else {             print("The session has completed activation.")         }     }          //[String: Any]     func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {         DispatchQueue.main.async {             let receivedState = message["State"] as? String ?? "Syncing"             print(receivedState)             self.messages.append(receivedState)         }     } }
Asked
by Gefei.
Last updated
.
Post not yet marked as solved
71 Views

UpdateApplicationContext Not Receiving updates

Hi community. It's my first time trying WatchConnectivity kit. When I attempt to send ApplicationContext from phone, my debug print indicates that updateApplicationContext is working correctly. However, I'm having trouble receiving it form the paired watch simulator as nothing is shown on that end. Here are the code for the Phone Extension:     func sendDataToWatch(data: String) {         state.append(data)         do {             NSLog("sent by phone")             try WCSession.default.updateApplicationContext(["currentstate": state])         }         catch {             print(error)         }     } Here are the code for watch: func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String: Any]) {         print("Hello")         if let getState = applicationContext["currentstate"] as? [String]{             print("\(getState)")             self.state = getState[0]         }     } Any suggestion would be appreciated!
Asked
by Gefei.
Last updated
.
Post not yet marked as solved
90 Views

watchOS 8 with iOS 14?

Apple says that watch OS 8 will work with iOS 14, however when I install 14.6, or even the 14.7 beta, I cannot pair with a watch running watchOS 8. It says my iPhone is out of date. Is this a beta-specific problem?
Asked Last updated
.
Post not yet marked as solved
47 Views

Unable to run watch app on Apple Watch simulator

When i try to activate the session all the time it fails, but succeeds in second attempt (both on device & simulator) Also, when i run on watch simulator it won't work as expected (It enters sendMessage() after the session get activated, and it goes into loading for long and then displays an error: "Message took too long") in Simulator (works fine on Device in Live app)
Asked Last updated
.
Post not yet marked as solved
419 Views

WatchOS 7.4 Beta : Simulator synced. UpdateApplicationContext() not working

Greetings fellow WatchOS app developers, On the iOS simulator running 12.5 beta, the method updateApplicationContext() claims that it succeeded, no exception is thrown and yet the WatchOS app, running on a WatchOS 7.4 simulator never gets its language session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) method invoked. Same issue in the other direction: The WatchOs app claims success on updating the iPhone app's application context. Yet nothing arrives. This works fine on real devices running iOS 14.5 beta and WatchOS 7.4 beta. Are there any workarounds? Due to Covid-19, I'm working remotely and can't debug on a real device, and need to be able to debug a critical WatchOS 7.4 specific issue. Thanks in advance!
Asked Last updated
.
Post not yet marked as solved
108 Views

Can I send a simple string from stand-alone watchOS app to a database (overkill), send via email or sms (preferable)?

Hello all - I have built my first watchOS stand-alone app. It tracks moments of motionlessness and if the (adjustable) threshold is not reached in 15, 30 and 45 seconds it triggers an event a, b, c. I am building a string that records the seconds elapsed and the event. May be 100 lines max. Is there a SIMPLE way to text, email, send, share this string from watchOS w/out building out an entire Eco-system that relies on the paired phone? I saw a tutorial about writing to icloudDrive, but after a day of returning a nil URL I read: Turns out watchOS does not support iCloud Drive at all, nor does it support the key-value storage iCloud service. Seriously, if I can just text it to myself I'd be happy. Note: This is only for proof-of-concept programming - this will never be in production - so hacks are welcome! Best, Dan
Asked Last updated
.
Post not yet marked as solved
150 Views

Sending realtime data from standalone Apple watch app to web application

For my bachelor's thesis, I chose to research the possibility to send real-time data from a standalone Apple Watch app to a web application. When researching how to do this I came up with 2 possibilities. The first one is sending the data with socket io to my Python backend server and using WebSockets to send it to the web application. The second option was using the WebRTC technology to create a peer-to-peer connection between the Watch and frontend. I chose to do the first one because of the complexity of using WebRTC for the first time and lost some time trying to implement it. I can't help to feel that there should be a better way to do this. As I'm reflecting on the project in my thesis I would like to know if anyone knows a better solution for this use case.
Asked Last updated
.
Post not yet marked as solved
217 Views

Apple Watch App not Displaying Back "<" Button

Hi, I'm currently developing an Apple Watch app with Swift and Storyboards. The main screen consists of three buttons going to three different view controllers. When I go to one view controller, it doesn't display the normal back "" button at the top-left corner, even though it works. I tried this with an older project, with a similar setup and it works as it should. I have no code to show because it works like it should. It seems to be with the storyboard. Anyone else have this problem? Thanks, Dan Uff The code is exactly the same in both projects, with
Asked Last updated
.
Post not yet marked as solved
287 Views

WCSession isComplicationEnabled() always false w simulator?

In my iOS app, I check to see if there's an active complication before sending complication data to the watch, given the limit of 50 transfers per day. It seems isComplicationEnabled() always returns false in the simulator, even though I have a watch app in a watchOS simulator that's active and running, with complications that actively get updated from the watch code as well. Data is successfully being passed from the simulated iPhone to the simulated watch app - both are active, connected and otherwise in sync. When I run using a physical device, WCSession isComplicationEnabled() on my iPhone does return true, but it seems to always be false in the simulator. Is this a limitation? Bug? Anyone else seeing this?
Asked
by ryoustra.
Last updated
.
Post not yet marked as solved
676 Views

WatchConnectivity for Xcode 12 / watchOS 7 / iOS 14 beta broken

While for watchOS 6 simulators the WCSession.default.transferFile(...) function from watchOS to iOS was already broken (FB7812483) while working flawlessly for watchOS 5 now with a Xcode 12 / watchOS 7 / iOS 14 beta combination that's still the case (FB7812526). Other things like WCSession.default.updateApplicationContext(...) are now also broken (FB7806876) which makes it basically impossible to work with WatchConnectivity and simulators for watchOS 7. I used https://developer.apple.com/documentation/watchconnectivity/using_watch_connectivity_to_communicate_between_your_apple_watch_app_and_iphone_app as an example project but originally discovered those problems in another app. I'm a big fan of Apple Watch but this situation makes it really hard to properly develop for it.
Asked
by Onranym.
Last updated
.