Skip to content

Commit

Permalink
Document directory flushing. Remove all downloaded documents on app e…
Browse files Browse the repository at this point in the history
…ntering background
  • Loading branch information
PRAN1999 committed Jan 14, 2019
1 parent 18213ff commit 539cbba
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SakaiClientiOS/Controllers/Announcement/AnnouncementDataFetcher.swift"
timestampString = "568602196.6907099"
timestampString = "568619912.786104"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "70"
Expand Down
5 changes: 2 additions & 3 deletions SakaiClientiOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func applicationDidEnterBackground(_ application: UIApplication) {

FileManager.default.clearDocumentsDirectory()
}

func applicationWillEnterForeground(_ application: UIApplication) {
Expand All @@ -48,8 +48,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if
// appropriate. See also applicationDidEnterBackground:.

}

func application(_ application: UIApplication,
Expand Down
2 changes: 1 addition & 1 deletion SakaiClientiOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>0.2.0</string>
<key>CFBundleVersion</key>
<string>1454</string>
<string>1460</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
22 changes: 22 additions & 0 deletions SakaiClientiOS/Models/Networking/DownloadService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ protocol DownloadService {
completion: @escaping (_ fileDestination: URL?) -> Void
)
}

extension FileManager {
func clearDocumentsDirectory() {
do {
guard
let documentsUrl = FileManager.default.urls(for: .documentDirectory,
in: .userDomainMask).first
else {
return
}
let documentDirectory = try contentsOfDirectory(atPath: documentsUrl.path)
try documentDirectory.forEach { file in
let fileUrl = documentsUrl.appendingPathComponent(file)
try removeItem(atPath: fileUrl.path)
}
} catch let err {
// TODO handle appropriately
print(err)
return
}
}
}

0 comments on commit 539cbba

Please sign in to comment.