Skip to content

Commit

Permalink
Always call startAccessingSecurityScopedResource()
Browse files Browse the repository at this point in the history
Should fix #7
  • Loading branch information
ColdGrub1384 committed Nov 21, 2018
1 parent ddf5410 commit 35710f5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Pisth.xcworkspace/xcshareddata/xcschemes/Pisth.xcscheme
Expand Up @@ -42,7 +42,7 @@
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
6 changes: 3 additions & 3 deletions Pisth/Info.plist
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the Photo Library for saving downloaded photos.</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDocumentTypes</key>
Expand Down Expand Up @@ -97,7 +95,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>3</string>
<string>5</string>
<key>Is Beta</key>
<string>$(IS_BETA)</string>
<key>LSApplicationQueriesSchemes</key>
Expand All @@ -113,6 +111,8 @@
</dict>
<key>NSFaceIDUsageDescription</key>
<string>This app requires Face ID permission to authenticate using Face recognition.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the Photo Library for saving downloaded photos.</string>
<key>NSUserActivityTypes</key>
<array>
<string>ch.marcela.ada.Pisth.openDirectory</string>
Expand Down
Expand Up @@ -1495,7 +1495,7 @@ class DirectoryCollectionViewController: UICollectionViewController, LocalDirect

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {

if urls.count == 1 {
if urls.count == 1 && urls[0].startAccessingSecurityScopedResource() {
documentPicker(controller, didPickDocumentAt: urls[0])
return
}
Expand Down
Expand Up @@ -617,6 +617,7 @@ class LocalDirectoryCollectionViewController: UICollectionViewController, UIDocu

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
for url in urls {
_ = urls[0].startAccessingSecurityScopedResource()
do {
try FileManager.default.copyItem(atPath: url.path, toPath: directory.appendingPathComponent(url.lastPathComponent).path)
reload()
Expand Down
Expand Up @@ -12,8 +12,8 @@ import MobileCoreServices
/// `ConnectionInformationTableViewController` that can import keys pair.
class PisthConnectionInformationTableViewController: ConnectionInformationTableViewController, UIDocumentPickerDelegate, Storyboard {

private let publicKeyPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeData as String], in: .open)
private let privateKeyPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeData as String], in: .open)
private let publicKeyPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeItem as String], in: .open)
private let privateKeyPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeItem as String], in: .open)

override var isUsernameRequired: Bool {
return false
Expand Down Expand Up @@ -103,6 +103,9 @@ class PisthConnectionInformationTableViewController: ConnectionInformationTableV
// MARK: - Document picker delegate

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {

_ = urls[0].startAccessingSecurityScopedResource()

if controller === publicKeyPicker {
publicKey = (try? String(contentsOf: urls[0]))
importPublicKeyBtn.setTitle(urls[0].lastPathComponent, for: .normal)
Expand Down

0 comments on commit 35710f5

Please sign in to comment.