0

I was wondering what the best practice for calling a function using NSUserdefaults is?

So basically I have a function in my main data model in my app that parses some data from an API.

I was able to pass the return value of this function through NSUserdefaults to transfer the data from my main app to my WatchKit app. However it only passes data when the App has been opened. How best can I call the function, to parse data from the API using Watchkit on it's own? (Like a background app open) I'm a bit confused.

Kind Regards,

Jack

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Welcome to SO. Your question doesn't make much sense. In WatchKit 1.0, the watch app is really just a second screen for your iPhone, managed by different types of controller objects. What is it that you are trying to communicate to the watch, what do you want the watch to do with it? – Duncan C Aug 18 '15 at 16:50
  • Thank you for your fast reply & welcome. Hi There @DuncanC basically my app pulls some information from an API and parses it into a string, I want to be able to access this information on my watch. So for example _iphone app_ pulls down IP Address of a server using a function A _watckit app_ displays Up to date IP Address pulled down from function A So how do I execute Function A in the background using my Watchkit app, Without having user to physically open the iPhone app. – Jack Leonard Aug 18 '15 at 18:29
  • Please check my answer in http://stackoverflow.com/a/31994232 – Vivienne Fosh Aug 30 '15 at 23:30

1 Answers1

0

Ok, your comments make things a little clearer.

You want to be able to have code that runs in your watch app that ask the phone for information.

If your watch app is running in a WKInterfaceController, you can use the WKInterfaceController method openParentApplication to send a request to the iPhone and get back a reply dictionary. If the phone is locked or your iPhone app is in the background, the message will be received by the iPhone from the background. Read up on the openParentApplication method in the Xcode docs for more information.

Duncan C
  • 128,072
  • 22
  • 173
  • 272