merlos/iOS-Open-GPX-Tracker

Crash when opening files browser

Opened this issue · 0 comments

The app crashes consistently for me when I tap the "folder" icon in the top left.
The view does show up, and shows one GPX file that I think I tried to import previously, but after the view has fully animated in, the app crashes with this error in the console:

OpenGpxTracker/GPXFileInfo.swift:23: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=257 "The file “ut-no_alsvik---skrussfjellet---nordland.gpx” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/Kart/ut-no_alsvik---skrussfjellet---nordland.gpx, NSFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Kart/ut-no_alsvik---skrussfjellet---nordland.gpx, NSUnderlyingError=0x301675200 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

I do still have a file in iCloud Drive named Kart/ut-no_alsvik---skrussfjellet---nordland.gpx, but for some reason the app doesn't have access to it?

I haven't tried reinstalling the app yet. That might fix it, but I thought I would report the bug so that it can get fixed!
When the app is in this state, I can save files, but they "go into the void". They don't show up in any folders in the Files app. The only way I've been able to get files out in this state is by sharing them through the share sheet instead.

I'm not that versed in Swift, but could it be that the issue is that .modifiedDate is called after customFolderURL.stopAccessingSecurityScopedResource() in this location?

if let customFolderURL = Preferences.shared.gpxFilesFolderURL {
_ = customFolderURL.startAccessingSecurityScopedResource()
files += self.fetchFilesList(from: customFolderURL)
customFolderURL.stopAccessingSecurityScopedResource()
}
return files.sorted { lhs, rhs in
return lhs.modifiedDate > rhs.modifiedDate
}