I'm trying to share cached data between a tvOS app and a TVService extension. I crated an app group and get a directory based on the identifier. All works fine in the simulator. On the tvOS dev kit however the app does not have write permission the app group directory.
I realize the restrictions on tvOS but shared cache data in app groups should be possible according the FAQ:
For temporary local storage, apps may access the NSTemporaryDirectory and NSCachesDirectory in their own container, or NSCachesDirectory in a shared container.
So how do I get access to the caches in the app group container? has anybody here got this working?
Indeed I found the solution: tvOS (like iOS and OS X) automatically creates Library/Caches inside of the app group container. The app has write permission for these directories just like for Library/Caches (aka NSCachesDirectory) in the app's container. As far as I know there is no way to get this URL programatically since NSFileManager.defaultManager().URLsForDirectory(.CachesDirectory, inDomains: .UserDomainMask) does only return the URL in the app's bundle.
So I reate this URL like this:
if let url = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(appGroupIdentifier) {
var cachesURL = url.URLByAppendingPathComponent("Library", isDirectory: true)
cachesURL = url.URLByAppendingPathComponent("Caches", isDirectory: true)
}
and the resulting directory is writable for the app