Reading a file in an AUV3 on iOS

Hi, should this be possible?

i.e. create a filechooser, select a file and then open it?

I’m trying this with no luck.

There’s lots of stuff on here about appgroups, security groups and sharing files between standalone and plugin, but I just need to be able to select a file and read it from the browser - is this allowed?

Thanks

1 Like

Can you be more specific?

AppGroups - allows sharing data between different apps. This is also relevant when you need a shared location (eg. Presets) between standalone and AUv3.

For reading files -
The browser should be enough. but from my experience iOS is very picky about what you pass as extensions so you need something like that:

For AppGroups/iCloud - you need a paid developer account.
For On-Device (On My iPhone/iPad) the files should be accessible even with the free developer program.

Edit:
Ohh, and you get a stream and not a real file. which is quite reasonable since a file can be “on the cloud” (eg. Dropbox/iCloud) and your pointer might be an inputstream that’s will be downloaded async.

1 Like

thx for your reply.

so basically, open a filechooser and select a file, something well known file type, e.g. “hello.xml”
try to open this using a FileInputStream - open fails.
try to open something included in the app bundle - open succeeds

FYI, errno is 1 - operation not permitted.
If I try to open a file that doesn’t exist errno is 2 - no such file

Here is what’s working for me. (for audio files)

I pass this from the chooser

importURL (chooser.getURLResult());
    void importURL (juce::URL url)
    {
#if JUCE_ANDROID
        auto androidDocument = juce::AndroidDocument::fromDocument (url);
        auto stream = androidDocument.createInputStream();
#else
        std::unique_ptr<juce::InputStream> stream (juce::URLInputSource (url).createInputStream());
#endif
        jassert (stream != nullptr);
        auto name = url.getFileName().upToLastOccurrenceOf (".", false, false);
        std::unique_ptr<juce::AudioFormatReader> reader (formatManager.createReaderFor (std::move (stream)));
       // do whatever I want with the result
    }
2 Likes

thx - will give that a go

works - thanks!