Share data in the document catalog in the iPhone and Watch app

How do I use application groups to exchange data, such as images, in a document catalog?

If this is not possible, what is the best way to exchange images between Watch App and iPhone? I can store binary image data in coredata, but this is not very efficient. I can also accomplish this using NSUserDefaults, but again this is not efficient.

+3


source to share


2 answers


Once you've set up your app group in Xcode (see Sharing Data with Your Companion iOS App ), you can get the path to the shared container / folder like this:

NSURL *groupContainerURL = [[NSFileManager defaultManager]
            containerURLForSecurityApplicationGroupIdentifier:@"YourAppGroupIdentifier"];
NSString *sharedDirectory = [groupContainerURL path];

      

Then, to write UIImage

(for example) to this folder:



NSData *imageData = UIImagePNGRepresentation(image);
NSString *filePath = [sharedDirectory stringByAppendingPathComponent:@"image.png"];
[imageData writeToFile:filePath atomically:YES];

      

You can use the same logic in both the Watch app and the iOS file sharing app. You can also create your own directories, since there is no "standard" directory structure for shared containers.

+8


source


Share data with app groups.

Easily share small amounts of data between your iOS app and your WatchKit Extension with App Groups and NSUserDefaults. To access other resources, such as the master data store, use a common container between your iOS app and the WatchKit extension to simplify access data and provide up-to-date information.



Take a look at the WatchKitt Application Architecture

0


source







All Articles