1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

File: Add helper function to locate shared containers on macOS and iOS

File::getContainerForSecurityApplicationGroupIdentifier will return the
path to a container which is shared between all apps using the specified
app group ID. This might be useful if you need to share resources
between a standalone app and an AUv3 plugin, for example.
This commit is contained in:
reuk 2021-08-25 18:51:03 +01:00
parent d738f0274e
commit b6ab931bcf
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
3 changed files with 20 additions and 1 deletions

View file

@ -1074,6 +1074,17 @@ public:
void addToDock() const;
#endif
#if JUCE_MAC || JUCE_IOS
/** Returns the path to the container shared by all apps with the provided app group ID.
You *must* pass one of the app group IDs listed in your app's entitlements file.
On failure, this function may return a non-existent file, so you should check
that the path exists and is writable before trying to use it.
*/
static File getContainerForSecurityApplicationGroupIdentifier (const String& appGroup);
#endif
//==============================================================================
/** Comparator for files */
struct NaturalFileComparator

View file

@ -506,4 +506,12 @@ void File::addToDock() const
}
#endif
File File::getContainerForSecurityApplicationGroupIdentifier (const String& appGroup)
{
if (auto* url = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier: juceStringToNS (appGroup)])
return File (nsStringToJuce ([url path]));
return File();
}
} // namespace juce

View file

@ -518,7 +518,7 @@ struct BackgroundDownloadTask : public URL::DownloadTask
void didFinishDownloadingToURL (NSURL* location)
{
NSFileManager* fileManager = [[NSFileManager alloc] init];
auto* fileManager = [NSFileManager defaultManager];
error = ([fileManager moveItemAtURL: location
toURL: createNSURLFromFile (targetLocation)
error: nil] == NO);