Watch Connectivity

RSS for tag

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

Posts under Watch Connectivity tag

195 Posts

Post

Replies

Boosts

Views

Activity

[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?
1
0
1.9k
Oct ’21
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?
1
0
878
Oct ’21
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
1
0
1k
Oct ’21
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.
1
0
3.9k
Oct ’21
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.
9
0
6.4k
Oct ’21
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.
1
0
882
Oct ’21
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
0
0
836
Sep ’21
Watch app cannot make direct requests without having the iPhone wifi on
Hey, I am building a watch only application which contains some api requests to be integrated such that data should be shown. I am using the apple watch se and I have turned on the wifi in the watch. But when I am making an api request for example, Guess I am trying to display a list and inorder to obtain that list I am required to make an api call from the watch app itself and I have written the required code. There are 4 different scenarios I tested and these are the results IPhone wifi on, watch wifi on - works IPhone wifi on, watch wifi off - works IPhone wifi off, watch wifi on - doesn't work Both switched off - doesn't work 1,2,4 can be accepted. But I am not sure why 3 is not working. I tested the app store in the watch as well following the above 4 scenarios and still the results are same. So my hypothesis is that it's the behavior of the watch. But i am not sure the reason why 3. is not working since I am making a standalone app and the watch supports wifi or internet connection why can't we directly pull data via the watch internet connectivity? Please someone who can elaborate the reason will be greatly appreciated. Thanks in advance!
3
1
2.7k
Sep ’21
Start iOS app in foreground from watch App, similar to camera app behavior
Hi! I've been working on a watch app/watch app extension for my iOS app. This app doesn't support running without an iOS app installation. It requires an app to work, it exposes certain controls to execute actions when the counterpart app (iOS app) is opened. I would like to add a similar interaction like the watchOS camera app and the iOS camera app have: when the iOS app is not active, for example in the background or not opened, show a button in the watch app to open the counterpart app in the foreground. I've been reading many posts about opening a counterpart app, and it looks like it is not possible, unless using Notifications, so it's the user that starts the action and put the app in the foreground. Some other developers suggests using Handoff, or WatchConnectivity sendMessage with reply handler. I haven't found a way to process an incoming message and transition the iOS app from background to foreground programmatically, not even with custom URLs. Is it possible for a third-party app not Apple built-in to have a similar experience like camera watchOS and iOS apps? Which APIs and mechanism should I use to achieve that behavior? Thanks!
0
0
990
Sep ’21
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.
15
0
3.3k
Sep ’21
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?
Replies
4
Boosts
0
Views
4.7k
Activity
Jan ’22
[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?
Replies
1
Boosts
0
Views
1.9k
Activity
Oct ’21
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?
Replies
1
Boosts
0
Views
842
Activity
Oct ’21
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?
Replies
1
Boosts
0
Views
878
Activity
Oct ’21
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
Replies
1
Boosts
0
Views
1k
Activity
Oct ’21
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.
Replies
1
Boosts
0
Views
3.9k
Activity
Oct ’21
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.
Replies
9
Boosts
0
Views
6.4k
Activity
Oct ’21
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.
Replies
1
Boosts
0
Views
882
Activity
Oct ’21
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
Replies
0
Boosts
0
Views
836
Activity
Sep ’21
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?
Replies
1
Boosts
0
Views
1k
Activity
Sep ’21
WCSession and CoreData
I have a problem with CoreData. Is there any way to directly save the data received by WCSession didreceiveuserinfo to CoreData?
Replies
0
Boosts
0
Views
632
Activity
Sep ’21
Watch app cannot make direct requests without having the iPhone wifi on
Hey, I am building a watch only application which contains some api requests to be integrated such that data should be shown. I am using the apple watch se and I have turned on the wifi in the watch. But when I am making an api request for example, Guess I am trying to display a list and inorder to obtain that list I am required to make an api call from the watch app itself and I have written the required code. There are 4 different scenarios I tested and these are the results IPhone wifi on, watch wifi on - works IPhone wifi on, watch wifi off - works IPhone wifi off, watch wifi on - doesn't work Both switched off - doesn't work 1,2,4 can be accepted. But I am not sure why 3 is not working. I tested the app store in the watch as well following the above 4 scenarios and still the results are same. So my hypothesis is that it's the behavior of the watch. But i am not sure the reason why 3. is not working since I am making a standalone app and the watch supports wifi or internet connection why can't we directly pull data via the watch internet connectivity? Please someone who can elaborate the reason will be greatly appreciated. Thanks in advance!
Replies
3
Boosts
1
Views
2.7k
Activity
Sep ’21
Start iOS app in foreground from watch App, similar to camera app behavior
Hi! I've been working on a watch app/watch app extension for my iOS app. This app doesn't support running without an iOS app installation. It requires an app to work, it exposes certain controls to execute actions when the counterpart app (iOS app) is opened. I would like to add a similar interaction like the watchOS camera app and the iOS camera app have: when the iOS app is not active, for example in the background or not opened, show a button in the watch app to open the counterpart app in the foreground. I've been reading many posts about opening a counterpart app, and it looks like it is not possible, unless using Notifications, so it's the user that starts the action and put the app in the foreground. Some other developers suggests using Handoff, or WatchConnectivity sendMessage with reply handler. I haven't found a way to process an incoming message and transition the iOS app from background to foreground programmatically, not even with custom URLs. Is it possible for a third-party app not Apple built-in to have a similar experience like camera watchOS and iOS apps? Which APIs and mechanism should I use to achieve that behavior? Thanks!
Replies
0
Boosts
0
Views
990
Activity
Sep ’21
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.
Replies
15
Boosts
0
Views
3.3k
Activity
Sep ’21
Share settings between standalone watch and iPhone app
Is it possible to share data/settings between an iPhone app and a standalone WatchOS app? Or have the watch app connect to the iOS app to send messages if available? I know how to do it the old way, but I'm moving my Watch app to be standalone and don't see how to communicate or share settings. Thanks
Replies
1
Boosts
0
Views
1.5k
Activity
Aug ’21