read
iOS introduced a way for users to transfer files from an app to a computer via iTunes.
It is simply adding UIFileSharingEnabled
to info.plist. There is a very small introduction here.
When you enable file sharing, ALL files in <Application_Home>/Documents
will be shared.
Users can copy files to and from the app, as well as delete.
So be cautious of that.
You might also want to monitor the directory. There is a way to do that using kqueue()
.
Write to directory (in Swift)
The API is via FileManager
.
// The Documents for every app
let documentDirectory = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
// Make sure you create any inner directories
let imageDirectory = documentDirectory.appendingPathComponent("/export/images/")
try! FileManager.default.createDirectory(at: imageDirectory, withIntermediateDirectories: true, attributes: nil)
// Write some data
try! data.write(to: imageDirectory.appendingPathComponent("lion.jpg"))
Simulator how?
If you want to access the app container on the simulator, you need to:
- Run on simulator
- Pause, and
po NSHomeDirectory()
- Open the directory in Finder and do whatever you want :)