Skip to content

Commit 1a584af

Browse files
committed
Added security scope handling
1 parent a0f1333 commit 1a584af

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

OpenGpxTracker/GPXFileManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class GPXFileManager: NSObject {
3636
let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
3737
var files = self.fetchFilesList(from: documentsURL)
3838
if let customFolderURL = Preferences.shared.gpxFilesFolderURL {
39+
_ = customFolderURL.startAccessingSecurityScopedResource()
3940
files += self.fetchFilesList(from: customFolderURL)
41+
customFolderURL.stopAccessingSecurityScopedResource()
4042
}
4143
return files.sorted { lhs, rhs in
4244
return lhs.modifiedDate > rhs.modifiedDate

OpenGpxTracker/Preferences.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ class Preferences: NSObject {
302302
var isStale: Bool = false
303303
let url = try URL(resolvingBookmarkData: bookmarkData, bookmarkDataIsStale: &isStale)
304304
if isStale {
305+
_ = url.startAccessingSecurityScopedResource()
306+
defer {
307+
url.stopAccessingSecurityScopedResource()
308+
}
305309
let newBookmark = try url.bookmarkData()
306310
_gpxFilesFolderBookmark = newBookmark
307311
defaults.set(newBookmark, forKey: kDefaultsKeyGPXFilesFolder)
@@ -318,6 +322,10 @@ class Preferences: NSObject {
318322
return
319323
}
320324
do {
325+
_ = newValue.startAccessingSecurityScopedResource()
326+
defer {
327+
newValue.stopAccessingSecurityScopedResource()
328+
}
321329
let newBookmark = try newValue.bookmarkData()
322330
_gpxFilesFolderBookmark = newBookmark
323331
defaults.set(newBookmark, forKey: kDefaultsKeyGPXFilesFolder)

0 commit comments

Comments
 (0)