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

46 results found
Sort by:
Post marked as solved
241k 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
61 Views

WatchConnectivity framework - Companion app is not installed

I created a pair of fairly simple apps (iOS and watchOS) that send messages to each other. It uses the WatchConnectiivity framework. When I run the two apps in the Simulator, I can send messages from the phone to the watch, but I cannot send messages from the watch to the phone. When I attempt that I get the message "Companion app is not installed". I've seen suggestions that I need to uncheck the "Supports Running Without iOS App Installation" checkbox, but when I do that, the iOS app no longer runs in the Simulator. My code is here: https://github.com/mvolkmann/watch-with-ios. I'd love to get some hints about how to work past this.
Asked
by mvolkmann.
Last updated
.
Post not yet marked as solved
319 Views

WCSession detect watch powered off. HealthKit startWatchApp hangs

Install app on phone and watch Power the watch off Run the app on the phone. WCSession.default.isWatchAppInstalled == true WCSession.isSupported() == true WCSession.default.isPaired == true WCSession.default.activationState == .activated Now I try to run HKHealthStore startWatchApp. The startWatchApp method's completion never fires. I'd like to detect that the watch is powered off, so then I do not try to run the startWatchApp method. I can't see a way to detect that the watch is powered off. Alternatively - I'd like startWatchApp to quickly fail, or - to have some way of cancelling it if it doesn't return quickly. Any ideas please?
Asked Last updated
.
Post not yet marked as solved
89 Views

UpdateApplicationContext not working simulator

I am having problems on Xcode13.3.1, Monterey 12.2.1, Apple M1 Max. Sending an UpdateApplicationContext update from a paired iPhone simulator is not received on the paired Apple Watch Simulator in the didRecieveApplicationContext. However, sendMessage from the apple watch simulator does update the iphone simulator app properly. It is however, not possible to send anything from the paired iPhone simulator to the paired Apple Watch Simulator. When working with actual devices everything works properly with WatchConnectivity with passing information back and forth via updateapplicationcontext and sendmessage calls. Can anyone confirm this is a bug or if there is something wrong with my setup?
Asked Last updated
.
Post not yet marked as solved
65 Views

Transfer EventKit Data from iOS to watchOS

Hi there, I am trying to transfer EventKit Data like EKCalendars / EKEvents / EKReminder from iOS to watchOS via WatchConnectivity. The connection works but I cannot push these objects directly in response. I also cannot use NSKeyedArchiver since EKCalendars (example) are not able to get converted to Data. So, any Idea how I can transfer simple EventKit Data from iOS to watchOS? An addtional hint: I am already fetching these data within watchOS (so no solution) but if the device has an MDM profile it cannot fetch anything but the holiday calendar so I just wanted to test if the iPhone can fetch more (since the MDM profile is stored on iPhone, not on watch) but I can't transfer these data trough WatchConnectivity. Any hints would be nice – cannot be as hard as I think. Thanks!
Asked
by caomhan.
Last updated
.
Post not yet marked as solved
1.3k 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
1.2k 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
146 Views

WatchConnectivity File Transfer is received but can’t find file on watch

I am successfully transferring a .mov file and the correct delegate is being called from the watch counterpart. Yet when I try to reference the URL of the file that was transferred, the file is can’t be found. Is there a specific file path that transferred files are saved to? Is there another way I can download a .mov file from my iPhone device to a counterpart?
Asked
by NO70.
Last updated
.
Post not yet marked as solved
388 Views

isCompanionAppInstalled isn't updating

Hi, I am building a companion watch os app and I want to check before sending a message from watch to phone, whether the app is installed on phone. But whenever I check for whether the companion app is installed it always returns true, even when I uninstall the mobile application (Please note this is a dependant app). Next I found out that in independant apps, watchconnectivity supports isCompanionAppInstalled, and then I ticked the extension to run as independant and then used the isCompanionAppInstalled. It always returns false regardless of whether the app is installed or not? I am not sure why this not working for either of the above 2 scenarios? How can we find whether the companion IOS app is installed in the device from the watch?
Asked
by Shehan_g.
Last updated
.
Post not yet marked as solved
4.1k 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
568 Views

WCSession counterpart app not installed

Basically i had an existing project developed using swift 5. I integrated watch app, and developed it using swift UI. Now i have followed all the required steps , even followed apple documentation, but i am getting connectivity issues between my watch app and ios app.I have created the session successfully , when i send a message form watch app to ios app, it send successfully , but when i send a message from ios app to watch app, i get the error "WCSession counterpart app not installed". I have verified and cross checked all the below items bundle identifiers are correctly placed Supports running without IOS App installation is also unchecked. Session is activated successfully I am activating the session in App delegate in applicationDidFinishLaunchingWithOptions on IOS App and in onAppear function of my watch app main class I have even tried creating a new project with the same configurations like my main project, i created a dummy app using swift and added a Swift UI watch extension just like i did in my main project. The catch is i am not facing any connectivity issue in this dummy app, watch and ios app are communicating perfectly, i can receive the message successfully on both the devices using the same lines of code which i use ion my main project. I would really appreciate if someone can help me in this, i have tried almost all the solutions and wasted almost a month on this issue. I have attached my WCSession Manager code WCSession Manager Here are the snippets of my code App Delegate WatchSessionManager.sharedManager.startSession() Watch App import SwiftUI @main struct AmbitBoxApp: App {     @SceneBuilder var body: some Scene {         WindowGroup {             NavigationView {                 HomeView()             }             .onAppear {                 WatchSessionManager.sharedManager.startSession()             }         }         WKNotificationScene(controller: NotificationController.self, category: "myCategory")     } }
Asked Last updated
.
Post not yet marked as solved
821 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 marked as solved
279 Views

Help with first watch app

I’m new to IOS development, and have spent the last month learning the development environment and the framework. I was able to successfully create a phone app with Xcode 13 that communicates with an autopilot I designed and built for my boat. It communicates with a BLE peripheral designed into the autopilot. All well, and good. The phone app includes a map and and allows for placing custom annotations on the map marking the location of fish I catch, or shallow spots on the lake. I decided it would be handy to have a watch app that would contain a few controls such as Lock onto the current heading, and turn left and right 10 degrees. Those functions are already implemented on the phone app, so I though it would be a simple task to send a message to the phone to activate those functions. For the life of me I can’t figure out how to send messages between the two apps. I backed up and created a simple phone app with a companion watch app. Same problem, no clue how to make them talk. I’ve searched online, but all the tutorials are way more complicated than what I need, and I can’t ferret the functionality I’m looking for from any of them. Can someone point me in the right direction to get started? Or if it’s not too involved, explain how to setup the link between the two apps.
Asked
by Weecabin.
Last updated
.
Post not yet marked as solved
253 Views

phone send message to watch fail

I have a app want to add watch extension,use WatchConnectivity is success when watch and phone all active,but it is fail when watch inactive. how to do phone can send message success or trigger watch shock when watch inactive
Asked
by PittWong.
Last updated
.
Post not yet marked as solved
187 Views

How receive data background if app not Running?

How receive data background if app not Running? Hell, I need recive data from iPhone to my app in Apple Watch background if apple Watch app not running. in extension Delegate I use these func  session(_ session: WCSession, didReceiveMessage message: [String : Any]) and session(_ session: WCSession, didReceiveMessageData messageData: Data, replyHandler: @escaping (Data) -> Void) if app on Apple Watch data not received.
Asked
by Radim007.
Last updated
.