|
I've gotten pretty far with a SwiftUI 2 app that reads a file of strings (with a specific file name) that is in the bundle. I've been looking to change it to use a document browser so that a local file (with any name, extension .inp) can be used (or perhaps on iCloud) and have gotten confused... SwiftUI 2 has new Doc Based App setup that includes a simple way to use a Document Group and edit a new document. I've changed the default from DocumentGroup(new document: ...) to DocumentGroup(viewing: ...) but a file that I'd like to choose is "greyed out" and it seems to only like files that were created with the DocumentGroup(new document: ...). In addition, I just want to get a browser to select a file; I don't think I need the @main file to set a scene for just this? So I think I just need a way to retreve the path (url?) to a file, and then I can read it, etc., with similar logic to reading the file that has a spefific name that is in the bundle. I'm surprised that I've not been able to find an example of something like this (or figure it out on my own...), but a pointer to an example would be welcomed! |
|
Since I posted this, I've made some progress, below, but now have a permissons issue that I'll describe. First, based on the iOS 14 release notes, there is a new .fileImporter() now available. I also modified code from a post by Aaron Wright at https://medium.com/better-programming/importing-and-exporting-files-in-swiftui-719086ec712 to get to just the code for importing a file.
This works great on the iPad simulator! However, when I run it on an actual iPad device, I get the error: Unable to read file contents The file “xyz.inp” couldn’t be opened because you don’t have permission to view it. This happens when I am trying a local file, or iCloud. I've tried to muck about with the info.plist for documents and either don't know what I'm doing, or perhaps this is not the path forward... |
|
I'm having the same issue and no luck so far, I would be interested in any solutions you found. |
|
I am having the same issue on iPhone (file import working on Simulator, not on physical device). Curious to hear if anyone found a solution to this. |
|
I had the same problem and think I may have found a Solution: You have to call
Note: Don't forget to call You can find more Infomation in the Apple Documentation. |
|
|
|
SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.