Skip to content

Commit

Permalink
delete photos and documents logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ValbuenaG committed Mar 23, 2023
1 parent 628aaeb commit 6007270
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
8 changes: 8 additions & 0 deletions Tella.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
3 changes: 1 addition & 2 deletions Tella/Components/ImagePickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class ImageCoordinator: NSObject, UINavigationControllerDelegate, UIImagePickerC
let mediaType = info[UIImagePickerController.InfoKey.mediaType] as AnyObject
debugLog("\(mediaType)")
let mediaURL = info[UIImagePickerController.InfoKey.mediaURL] as? URL
let imageURL = info[UIImagePickerController.InfoKey.imageURL] as? URL

let imageURL = info[UIImagePickerController.InfoKey.referenceURL] as? URL
if mediaType as! CFString == kUTTypeImage {
guard let unwrapImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import Foundation
import UIKit
import SwiftUI
import Photos

class PhotoVideoViewModel : ObservableObject {

Expand All @@ -29,6 +30,10 @@ class PhotoVideoViewModel : ObservableObject {
to: self.mainAppModel.vaultManager.root,
type: type,
folderPathArray: self.folderPathArray)

if mainAppModel.importOption == .deleteOriginal {
removeFiles(files: files)
}
DispatchQueue.main.async {

self.resultFile?.wrappedValue = vaultFile
Expand All @@ -53,15 +58,10 @@ class PhotoVideoViewModel : ObservableObject {
//remove originalURL from phone

if mainAppModel.importOption == .deleteOriginal {
if let originalUrl = originalUrl {
do {
print("removing file: \(originalUrl)")
try FileManager.default.removeItem(at: originalUrl)
} catch {
print("Error removing file: \(error)")
}
}
}
let imageUrls = [originalUrl].compactMap{$0}
removeOriginalImage(imageUrls: imageUrls)

}
DispatchQueue.main.async {
self.resultFile?.wrappedValue = vaultFile
}
Expand All @@ -71,4 +71,24 @@ class PhotoVideoViewModel : ObservableObject {
}
}
}

func removeOriginalImage(imageUrls: [URL]) {
PHPhotoLibrary.shared().performChanges( {
let imageAssetToDelete = PHAsset.fetchAssets(withALAssetURLs: imageUrls, options: nil)
PHAssetChangeRequest.deleteAssets(imageAssetToDelete)
},
completionHandler: { success, error in
print("Finished deleting asset. %@", (success ? "Success" : error as Any))
})
}

func removeFiles(files: [URL]) {
for file in files {
do {
try FileManager.default.removeItem(at: file)
} catch {
print("Error deleting file: \(error.localizedDescription)")
}
}
}
}
16 changes: 10 additions & 6 deletions Tella/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<dict>
<key></key>
<array/>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand All @@ -22,6 +26,8 @@
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSRequiresIPhoneOS</key>
Expand All @@ -30,6 +36,10 @@
<string>Tella requires access to the camera to to take photos and videos inside the app.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Tella requires access to your microphone to record audio inside the app.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string></string>
<key>NSPhotoLibraryUsageDescription</key>
<string></string>
<key>UIAppFonts</key>
<array>
<string>OpenSans-Italic.ttf</string>
Expand Down Expand Up @@ -78,11 +88,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
</dict>
</plist>

0 comments on commit 6007270

Please sign in to comment.