How to share data between iPhone and Apple Watch using groups?
i am new to Watchkit development and unable to find solution to share data between iPhone and iWatch, please help me
i am looking to share data using groups.
2 Solutions Collect From Internet About “How to share data between iPhone and Apple Watch using groups?”
We can pass the data between iPhone & iWatch using groups.
Basically iWatch can not do any processing and we need to share the data. We can share data using the
But for that you need to enable
Appp Groups from capabilities section in both your project target and your iwatch app target, as showed below
Below is the sample code to achieve that.
viewController or appDelegate file add following code
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.test.yourapp"]; [myDefaults setObject:@"aadil" forKey:@"name"];
Basically you are setting the value
Next step is to write code to retrieve that as below
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.test.yourapp"]; [myDefaults objectForKey:@"name"];
Hope this helps 🙂
WARNING! It’s not working with WatchOS 2 anymore, use methods from WatchConnectivity Framework. The best is updateApplicationContext: which always keep the latest data alive. From Apple doc:
Watch apps that shared data with their iOS apps using a shared group
container must be redesigned to handle data differently. In watchOS 2,
each process must manage its own copy of any shared data in the local
container directory. For data that is actually shared and updated by
both apps, this requires using the Watch Connectivity framework to
move that data between them.
- Resizing UITableView to fit content
- iOS framework/library for presenting Powerpoint slides?
- React Native “Could not connect to development server.”
- Realm Swift: always put nil values last in sort
- Swift startsWith method?
- How to create a Today widget programmatically without storyboard on iOS8?
- listing all files from specified folders in Google Drive through IOS Google Drive SDK
- Different cell bg color depending on iOS version (4.0 to 5.0)
- Arabic Strings reversed in xcode
- How can I use swift in Terminal?
- Are complex indexes possible when using Core Data?
- iOS App Extension – Action – Custom Data
- NSString retain Count
- Max length UITextField
- Segmented control to toggle through multiple tableviews