19947

Pass text from iOS label to WatchOS label - swift-

Question:

I've a problem, with my app.. I try to follow some guide like <a href="https://stackoverflow.com/questions/27025526/passing-data-to-apple-watch-app/32002403#32002403" rel="nofollow">Passing data to Apple Watch app</a> , but I'm not sure it will fit for my case. I've some label with text on my iOS app, then I want to show this text on my watchOS app label, and I don't know which is the best way to pass this text and keep it synchronized with the iOS app.. Thanks a lot for your help!

Answer1:

Since watchOS2, you don't have any built in function for communicating between the iOS and watchOS app than the WatchConnectivity framework.

From the information provided in your question, the <a href="https://developer.apple.com/documentation/watchconnectivity/wcsession/1615621-updateapplicationcontext" rel="nofollow">updateApplicationContext(_:)</a> function seems to be the best solution for your problem. You can send a dictionary of data with this function and the system tries to make sure that the data is received by the time your app is displayed to the user. If the function is called several times before the app would be visible to the user (run in the foreground), the system overwrites the previous data, so the Watch app only receives the most recent data to display.

Answer2:

For watchOS1, Since Watch App is included as an extension in your Host App. So, you can use App Group to share data between your Host App and your App Extension.

Refer to <a href="https://stackoverflow.com/a/44654185/5716829" rel="nofollow">https://stackoverflow.com/a/44654185/5716829</a> for more on using App Groups.

Answer3:

The right method for this is WCSession.updateApplicationContext(_ applicationContext: [String : Any]) <a href="https://developer.apple.com/documentation/watchconnectivity/wcsession/1615621-updateapplicationcontext" rel="nofollow">https://developer.apple.com/documentation/watchconnectivity/wcsession/1615621-updateapplicationcontext</a> "Sends a dictionary of values that a paired and active device can use to synchronize its state."

Recommend

  • How come struts property tag converts java.util.Date in m/d/yy format
  • Shell environment variables in vagrant files are only passed on first up
  • 3.0.0.M1 how to run on https connection
  • Vue.js / webpack creates no build file?
  • Select values within/outside of a set of intervals (ranges) R
  • Word 2007 VBA: ActiveDocument.CustomXMLParts
  • How do I deploy application on sourcevoid with private git package dependencies?
  • Why is the COM interface contract immutable?
  • Getting the min and max values from a PHP array
  • regex question for removal of javascript malware
  • How can I see Python's __builtins__ source code?
  • How can I include multiple models in one view for in a Joomla 3.x component built with Component Cre
  • Is there a way to clear some session data from ALL sessions?
  • PHP & cURL proxy - how to make multi-user cookie jar?
  • Is it possible to disable jQuery's mobile responsive design?
  • In VIm, how to remove all lines that are duplicate somewhere?
  • `docker cp` doesn't copy file into container
  • How can I use a custom function within an expression using the eval dataframe method?
  • Can my app be notified when another application starts/stops playing audio?
  • Available space left on drive - WinAPI - Windows CE
  • jquery validation - waiting for remote check to complete
  • How do I display a dialog that asks the user multi-choice questıon using tkInter?
  • how does System.Web.HttpRequest::PathInfo work?
  • Scala multiline string placeholder
  • Does Mobilefirst provide a provision to access web services directly?
  • Blackberry - Custom EditField Cursor
  • Content-Length header not returned from Pylons response
  • Ajax Loaded meta Tags
  • Lost migrations and Azure database is now out of sync
  • Xamarin Forms - UWP Fonts
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • How would I use PHP exceptions to define a redirect?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Web-crawler for facebook in python
  • Arrays break string types in Julia
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Proper folder structure for lots of source files
  • Net Present Value in Excel for Grouped Recurring CF