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

58 results found
Sort by:
Post marked as solved
168k 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
29 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
641 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
437 Views

[Apple Watch Connectivity Demo App] Application context only received on phone

I'm currently learning how to use WatchConnectivity to send data from the iPhone companion app to the Watch extension. I watched the talk "Introducing Watch Connectivity" from WWDC 2015 and downloaded the example project provided by Apple which demonstrates the different WC capabilities. For my specific use case I'm particularly interested in updating the application context on the phone and receiving it on the watch. When I launch the demo app on the phone/watch simulator I see a "Update App Context" button in both UIs. My understanding is that pressing this button for instance on the phone will call the session's delegate callback didReceiveApplicationContext on the watch on the next app launch. While this works as expected the other way round, meaning pressing the button on the watch first and receiving the application context on the phone on app launch, I can't get it to work with the context being sent from the phone to the watch. The breakpoint in didReceiveApplicationContext is never hit. I also noticed that when I set a breakpoint in activationDidCompleteWith on the watch the session property paired and watchAppInstalled are set to false: However both of these properties are true on the phone: I did not touch any of the code in the demo app, just set breakpoints to understand what's going on. My question is: Is it possible to update the application context in both directions?
Asked
by kersten83.
Last updated
.
Post not yet marked as solved
125 Views

How to revert a standalone watch app to a dependant watch app

Hi, I have created a watch only app and would need to convert it to a dependant watch app since I need to exchange data via watch connectivity? How can we convert such kind of an app? Is it possible without creating a new app, by only changing the required settings in the existing app?
Asked
by Shehan_g.
Last updated
.
Post not yet marked as solved
138 Views

Is it safe to pass data via watchConnectivity

Hi, I am developing a dependant watch app and need to pass some data from the phone to watch and vice versa to sync up(Imagine login credentials). So is it secure to pass data as plain text from the mobile to watch app and vice versa? Can hackers or middleman can listen and gain the data within the communication process? Or is the data encrypted by any means default by apple?
Asked
by Shehan_g.
Last updated
.
Post not yet marked as solved
356 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 marked as solved
167 Views

How to decrypt in swift using CommonCrypto

I am building an IOS app and it communicates with the JS. So the communication between the two ends must be encrypted. So my main intention is to encrypt from Javascript side and send it to the IOS app mobile end, and the mobile app should decrypt the data. This is how I have done on Javascript side and it works fine as expected, const key = CryptoJS.enc.Utf8.parse("1111111111111111"); const iv = CryptoJS.enc.Utf8.parse("ui09ji884uh88984"); var encrypted = CryptoJS.AES.encrypt("Hello world",key, { mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, iv: iv }); console.log("Encrypted data ="+encrypted); The issue is how I can decrypt this encrypted data in swift using CommonCrypto. Since this is plain base64 text how can we feed it to decryption? The code I have done so far in swift is posted below, func testCrypt(data data:[UInt8], keyData:[UInt8], ivData:[UInt8], operation:Int) -> [UInt8]? { let cryptLength = size_t(data.count+kCCBlockSizeAES128) var cryptData = [UInt8](repeating: 0, count:cryptLength) let keyLength = size_t(kCCKeySizeAES128) let algoritm: CCAlgorithm = UInt32(kCCAlgorithmAES128) let options: CCOptions = UInt32(kCCOptionPKCS7Padding) var numBytesEncrypted :size_t = 0 let cryptStatus = CCCrypt(CCOperation(operation), algoritm, options, keyData, keyLength, ivData, data, data.count, &cryptData, cryptLength, &numBytesEncrypted) if UInt32(cryptStatus) == UInt32(kCCSuccess) { // cryptData.remove cryptData.removeSubrange(numBytesEncrypted..<cryptData.count) } else { print("Error: \(cryptStatus)") } return cryptData; } This is the way I have called the above method, let message    = "HEY" let messageData  = Array(message.utf8) let keyData    = Array("1111111111111111".utf8) let ivData    = Array("ui09ji884uh88984".utf8)            let str = "SJeOvypKWad9GzUD2GHRig==" let buf: [UInt8] = Array(str.utf8)           print("BUFF: ",buf)             let encryptedData = testCrypt(data:messageData,  keyData:keyData, ivData:ivData, operation:kCCEncrypt)!          let decryptedData = testCrypt(data:buf, keyData:keyData, ivData:ivData, operation:kCCDecrypt)! var decrypted   = String(bytes:decryptedData, encoding:String.Encoding.utf8)! This works fine if we do both the encryption and decryption and passing the encrypted byte array for decryption. But when I try to convert the encrypted text in to a byte array and passing it to it, an exception occurs. And also the one which I convert (eg: buf) and which the testCrypt returns after encrypting (eg: encryptedData) isn't similar. Please can anyone elaborate this and provide a solution will be greatly appreciated.
Asked
by Shehan_g.
Last updated
.
Post marked as solved
479 Views

help me! (data sync between watch and phone)

I'm making an Apple Watch app and an iPhone app. The structure of the app is as follows. (On Apple Watch) Count the number and store it in Userdefault.(title, number) (On Apple Watch) Press the 'Count Complete' button to send the title and number data to the iPhone app. (In the iPhone app) Save the data received from the Apple Watch as CoreData. Here's the problem. I don't know the proper way to transfer the data (title, number) generated by the Apple Watch to the iPhone.
Asked
by nubkordev.
Last updated
.
Post not yet marked as solved
172 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
191 Views

How much time will it take approximately to receive a reply after a message is sent in WCSession

Hi, I am currently building a companion watch application and I use wcsession to exchanges some data within the IOS app and watchOS app. I want to know how much time maximum it would take to send a message and receive a response? Because we can't hold the user infinitely until the watch receives the necessary data? So is it handled from the wcsession itself, like sending out a timeout exception or is it necessary to handle from the developer end? If it is can anyone add a possible solution. Thanks.
Asked
by Shehan_g.
Last updated
.
Post not yet marked as solved
2.5k 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 { &#9;&#9;@IBOutlet weak var messageLabel: UILabel! &#9;&#9;fileprivate var wcSession: WCSession! &#9;&#9;override func viewDidLoad() { &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;&#9;&#9;wcSession = WCSession.default &#9;&#9;&#9;&#9;wcSession.delegate = self &#9;&#9;&#9;&#9;wcSession.activate() &#9;&#9;} &#9;&#9;@IBAction func sendMessageAction(_ sender: Any) { &#9;&#9;&#9;&#9;let message = [ &#9;&#9;&#9;&#9;&#9;&#9;"content": "Message sent from iPhone on \(Date())." &#9;&#9;&#9;&#9;] &#9;&#9;&#9;&#9;wcSession.sendMessage(message, replyHandler: nil, errorHandler: { error in &#9;&#9;&#9;&#9;&#9;&#9;print("Error when sending message: \(error.localizedDescription)") &#9;&#9;&#9;&#9;}) &#9;&#9;} } extension ViewController: WCSessionDelegate { &#9;&#9;func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { &#9;&#9;&#9;&#9;switch activationState { &#9;&#9;&#9;&#9;case .activated: &#9;&#9;&#9;&#9;&#9;&#9;print("WCSession activated successfully") &#9;&#9;&#9;&#9;case .inactive: &#9;&#9;&#9;&#9;&#9;&#9;print("Unable to activate the WCSession. Error: \(error?.localizedDescription ?? "--")") &#9;&#9;&#9;&#9;case .notActivated: &#9;&#9;&#9;&#9;&#9;&#9;print("Unexpected .notActivated state received after trying to activate the WCSession") &#9;&#9;&#9;&#9;@unknown default: &#9;&#9;&#9;&#9;&#9;&#9;print("Unexpected state received after trying to activate the WCSession") &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;func session(_ session: WCSession, didReceiveMessage message: [String : Any]) { &#9;&#9;&#9;&#9;guard let content = message["content"] as? String else { return } &#9;&#9;&#9;&#9;DispatchQueue.main.async { &#9;&#9;&#9;&#9;&#9;&#9;self.messageLabel.text = content &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;func sessionDidBecomeInactive(_ session: WCSession) { &#9;&#9;} &#9;&#9;func sessionDidDeactivate(_ session: WCSession) { &#9;&#9;} } Code on the Watch Kit app: import WatchKit import Foundation import WatchConnectivity class InterfaceController: WKInterfaceController { &#9;&#9;@IBOutlet weak var messageLabel: WKInterfaceLabel! &#9;&#9;fileprivate var wcSession: WCSession! &#9;&#9;override func awake(withContext context: Any?) { &#9;&#9;&#9;&#9;wcSession = WCSession.default &#9;&#9;&#9;&#9;wcSession.delegate = self &#9;&#9;&#9;&#9;wcSession.activate() &#9;&#9;} &#9;&#9;@IBAction func sendMessageAction() { &#9;&#9;&#9;&#9;let message = [ &#9;&#9;&#9;&#9;&#9;&#9;"content": "Message sent from Watch on \(Date())." &#9;&#9;&#9;&#9;] &#9;&#9;&#9;&#9;wcSession.sendMessage(message, replyHandler: nil, errorHandler: { error in &#9;&#9;&#9;&#9;&#9;&#9;print("Error when sending message: \(error.localizedDescription)") &#9;&#9;&#9;&#9;}) &#9;&#9;} } extension InterfaceController: WCSessionDelegate { &#9;&#9;func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { &#9;&#9;&#9;&#9;switch activationState { &#9;&#9;&#9;&#9;case .activated: &#9;&#9;&#9;&#9;&#9;&#9;print("WCSession activated successfully") &#9;&#9;&#9;&#9;case .inactive: &#9;&#9;&#9;&#9;&#9;&#9;print("Unable to activate the WCSession. Error: \(error?.localizedDescription ?? "--")") &#9;&#9;&#9;&#9;case .notActivated: &#9;&#9;&#9;&#9;&#9;&#9;print("Unexpected .notActivated state received after trying to activate the WCSession") &#9;&#9;&#9;&#9;@unknown default: &#9;&#9;&#9;&#9;&#9;&#9;print("Unexpected state received after trying to activate the WCSession") &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;func session(_ session: WCSession, didReceiveMessage message: [String: Any]) { &#9;&#9;&#9;&#9;guard let content = message["content"] as? String else { return } &#9;&#9;&#9;&#9;messageLabel.setText(content) &#9;&#9;} }
Asked
by matiasb.
Last updated
.
Post not yet marked as solved
179 Views

iOS 15 and WatchOS 8 apps WCSession connectivity issue

Sometime I am facing issue in WCSession. Watchkit app can send ping to iPhone app using WCSession, and it successfully received by the iPhone app but send back the information to watch from iPhone is not received by the watch. (void)session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *, id> *)message replyHandler:(void(^)(NSDictionary<NSString *, id> *replyMessage))replyHandler{ //iOS App to watch call back failed } then if I kill the watch app then start again it works fine. but after 2-3 hrs again facing connectivity WCSession issue
Asked
by dsn.geu.
Last updated
.
Post not yet marked as solved
2.5k 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 marked as solved
211 Views

iPhone can’t communicate with Apple Watch

When trying to turn on the option to unlock my iPhone with my watch I get a communication error. iPhone on iOS 15.1 and watch on 8.1. Both connected as re-paired a number of times and alerts being received on both. anyone found how to fix this?
Asked
by perkstvr3.
Last updated
.