Created
January 28, 2021 01:38
-
-
Save takiguri/39801f10b12b1dfbef7e9b9a2fd93efe to your computer and use it in GitHub Desktop.
Allow app to access Files app by creating its own app folder using the FileManager framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Step 1: info.plist, set: | |
UIFileSharingEnabled = YES | |
LSSupportsOpeningDocumentsInPlace = YES | |
*/ | |
/** | |
Step 2: I used a pod that is a thin wrapper over FileManager, created by Sundell | |
Podfile, set | |
pod 'Files', '~> 4.0.2' | |
*/ | |
/** | |
Step 3: In AppDelegate | |
*/ | |
import Files // Files pod by Sundell | |
// Access the document directory using FileManager | |
let docsDirUrl = try! FileManager.default.url(for: .documentDirectory, | |
in: .userDomainMask, | |
appropriateFor: nil, | |
create: true) | |
// Using files, access the document folder by using its folder url path | |
let docsFolder = try! Folder(path: docsDirUrl.path) | |
// Check if the docs folder has a subfolder for the app name | |
if docs.constainsSubfolder(named: App.displayName) { | |
// If it does, make sure a folder is printed with the App.displayName | |
docs.subfolders.recursive.forEach { print($0.name) } | |
} else { | |
let appFolder = try! docs.createSubfolder(named: App.displayName) | |
// Make sure a folder is printed with the App.displayName | |
docs.subfolders.recursive.forEach { print($0.name) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment