My Photo Sharing extension plans to use the same design assets (for navigation and for adding 'stamps / stickers' to the photo).
As explained in App Sandbox Design Guide, groups of sandboxed apps that need to share files and other information can request a container directory as part of their entitlements. These directories are stored in ~/Library/Group Containers/. https://developer.apple.com/documentation/foundation/nsfilemanager/1412643-containerurlforsecurityapplicati
Currently the assets are bundled in or downloaded and added to the Documents
folder. If I want to use the assets in the Photo Sharing extension, would it make sense to put everything in the ~/Library/Group Containers/
and both the container app and the extension get the assets from there?
Sounds like you want to use a framework instead. Your framework will be primarily resources instead of code, however:
https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPFrameworks/Frameworks.html#//apple_ref/doc/uid/10000183i
here the steps to resolve your issue:
go to xcode open your app which contains the app extension feature
go to target in your xcode project and select your app extension name
go to build phases
expand the copy bundle resources then click "+" button and add the image assets folder from the finder.
Regarding sharing data:
If you want to share files between your iOS8 extension and your Containing app, you want to write files to a shared container or use the shared user defaults.
From Apple's iOS8 current documentation:
You want to create an App Group, and add your containing app and its extensions to this group. This is pretty simple using Xcode 6, here's how to do it in xcode:
In the app group name, input a constant like:
This creates a shared container for your containing app and extension, which allows:
Share NSUserDefaults:
Share a directory on the filesystem:
EDIT This will print out all the path combinations we have:
EDIT - and for Swift:
Share NSUserDefaults:
Share a directory on the filesystem:
I hope this helps you :)
Resources: Apple's iOS8.0 Extensions Development Guide - https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1
Apple's iOS8.0 NSFileManager Class Reference - https://developer.apple.com/documentation/foundation/nsfilemanager/1412643-containerurlforsecurityapplicati
I need to share bundled resources between the app and extension. At first, I was thinking I could copy them into the shared group area on first launch, but what if the user calls up the extension and never launches the app?
As mxcl notes, you can include the assets in both targets but that will expand the size of your final submitted binary.
I've confirmed putting assets in a framework works in Xcode 6.1 (it may have worked before, but I'm just trying it now):
You can have standalone images in your framework or an asset catalog. Both will work.
In the framework, just set up a class with accessor methods that return
UIImage
objects. Something like this (Objective-C):Or in Swift:
Note that since the above code is inside the framework but will run in "app space" you need to specify the bundle.
Then, your app or extension can just link in the framework, and call
[AssetService frameworkImageNamed:@"myimage"]
orAssetService.frameworkImageNamed("myimage")
.Caveat: despite returning an optional
UIImage?
the code gets very angry if it can't find the image named and will crash. But if it's your own framework, you should know what's in there and catch this kind of bug.