How to share data between iPhone and Apple Watch using groups?

I am new to Watchkit development and cannot find a solution for exchanging data between iPhone and iWatch, please help me. I want to share data using groups.

+4
source share
2 answers

We can transfer data between iPhone and iWatch using groups.

Basically, iWatch cannot do any processing, and we need to exchange data. We can exchange data using NSUserDefaults.

But for this you need to include Appp Groupsfrom the capabilities section both in your target project goal and in the iwatch target application, as shown below

App Groups

.

viewController or appDelegate

 NSUserDefaults *myDefaults = [[NSUserDefaults alloc]
                               initWithSuiteName:@"group.test.yourapp"];
[myDefaults setObject:@"aadil" forKey:@"name"];

"aadil" "name".

- ,

 NSUserDefaults *myDefaults = [[NSUserDefaults alloc]
                               initWithSuiteName:@"group.test.yourapp"];
[myDefaults objectForKey:@"name"];

, :)

+11

! WatchOS 2, WatchConnectivity Framework. updateApplicationContext:, . Apple:

, iOS -. watchOS 2, . , , Watch Connectivity .

+4

All Articles