Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communication with watch kit extension and iPhone app

I tried to send data from iPhone app to watch kit extension but fail. And have no idea how to do it.

I tested on simulator and send data via app groups.

Here is my steps:

  1. download watch kit catalog sample app from apple
  2. Add App groups (XXX.XXX.XXX) for iPhone app and wtach kit extension
  3. Add RequestOpenAccess: YES for NSExtensionAttributes (watch kit extension)
  4. Add a button to iPhone app that will write a value to NSUserDefaults with the specific Suite Name
  5. Add code at watchkit extension to read NSUserDefaults data. ([NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:)

  6. Run watch kit app

  7. manual click the Catalog app in the iPhone simulator
  8. click the button added at step 4
  9. add break point at watchkit extension to see if the NSUserDefaults value changed
  10. Nothing happen

What necessary things I miss?

Or I should use another way to do this?

All I want to do is to send data from iPhone to watch every seconds. The data could be string or image.

Thanks

like image 686
Ecroo Avatar asked Nov 21 '14 08:11

Ecroo


1 Answers

To set communication between iPhone and iWatch I have been putting a file into the shared app group folder and monitor it from the Watch extension. If there is any change in iPhone app it modifies the file and the Watch extension will be notified and can act on it.

like image 149
Nayana Avatar answered Sep 16 '22 18:09

Nayana