|
@@ -57,6 +57,7 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
|
|
|
|
|
|
var localServerUrl : String?
|
|
var localServerUrl : String?
|
|
var thumbnailInLoading = [String: IndexPath]()
|
|
var thumbnailInLoading = [String: IndexPath]()
|
|
|
|
+ var destinationURL : URL?
|
|
|
|
|
|
lazy var networkingOperationQueue : OperationQueue = {
|
|
lazy var networkingOperationQueue : OperationQueue = {
|
|
|
|
|
|
@@ -362,9 +363,8 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
|
|
func uploadFileSuccess(_ fileID: String!, serverUrl: String!, selector: String!, selectorPost: String!) {
|
|
func uploadFileSuccess(_ fileID: String!, serverUrl: String!, selector: String!, selectorPost: String!) {
|
|
|
|
|
|
hud.hideHud()
|
|
hud.hideHud()
|
|
- let url = URL(string: "file://\(directoryUser!)/\(fileID!)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!)
|
|
|
|
|
|
|
|
- dismissGrantingAccess(to: nil)
|
|
|
|
|
|
+ dismissGrantingAccess(to: self.destinationURL)
|
|
}
|
|
}
|
|
|
|
|
|
// MARK: - Download Thumbnail
|
|
// MARK: - Download Thumbnail
|
|
@@ -424,26 +424,37 @@ extension DocumentPickerViewController {
|
|
|
|
|
|
let fileName = sourceURL.lastPathComponent
|
|
let fileName = sourceURL.lastPathComponent
|
|
|
|
|
|
- guard let destinationURL = URL(string: "file://\(directoryUser!)/\(fileName)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!) else {
|
|
|
|
|
|
+ guard let destinationURLDirectoryUser = URL(string: "file://\(directoryUser!)/\(fileName)".addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!) else {
|
|
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ self.destinationURL = appGroupContainerURL()?.appendingPathComponent(fileName)
|
|
|
|
+
|
|
|
|
+ // copy sourceURL on DirectoryUser
|
|
|
|
+ do {
|
|
|
|
+ try FileManager.default.removeItem(at: destinationURLDirectoryUser)
|
|
|
|
+ } catch _ {
|
|
|
|
+ print("file do not exists")
|
|
|
|
+ }
|
|
|
|
+ do {
|
|
|
|
+ try FileManager.default.copyItem(at: sourceURL, to: destinationURLDirectoryUser)
|
|
|
|
+ } catch _ {
|
|
|
|
+ print("file do not exists")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
fileCoordinator.coordinate(readingItemAt: sourceURL, options: .withoutChanges, error: nil, byAccessor: { [weak self] newURL in
|
|
fileCoordinator.coordinate(readingItemAt: sourceURL, options: .withoutChanges, error: nil, byAccessor: { [weak self] newURL in
|
|
|
|
|
|
// Remove destination file
|
|
// Remove destination file
|
|
do {
|
|
do {
|
|
-
|
|
|
|
- try FileManager.default.removeItem(at: destinationURL)
|
|
|
|
-
|
|
|
|
|
|
+ try FileManager.default.removeItem(at: (self?.destinationURL)!)
|
|
} catch _ {
|
|
} catch _ {
|
|
-
|
|
|
|
print("file do not exists")
|
|
print("file do not exists")
|
|
}
|
|
}
|
|
|
|
|
|
do {
|
|
do {
|
|
-
|
|
|
|
- try FileManager.default.copyItem(at: sourceURL, to: destinationURL)
|
|
|
|
|
|
+ try FileManager.default.copyItem(at: sourceURL, to: (self?.destinationURL)!)
|
|
|
|
|
|
// Upload fileName to Cloud
|
|
// Upload fileName to Cloud
|
|
|
|
|
|
@@ -473,6 +484,32 @@ extension DocumentPickerViewController {
|
|
dismiss(animated: true, completion: nil)
|
|
dismiss(animated: true, completion: nil)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ func appGroupContainerURL() -> URL? {
|
|
|
|
+
|
|
|
|
+ let fileManager = FileManager.default
|
|
|
|
+ guard let groupURL = fileManager
|
|
|
|
+ .containerURL(forSecurityApplicationGroupIdentifier: capabilitiesGroups) else {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let storagePathUrl = groupURL.appendingPathComponent("File Provider Storage")
|
|
|
|
+ let storagePath = storagePathUrl.path
|
|
|
|
+
|
|
|
|
+ if !fileManager.fileExists(atPath: storagePath) {
|
|
|
|
+ do {
|
|
|
|
+ try fileManager.createDirectory(atPath: storagePath,
|
|
|
|
+ withIntermediateDirectories: false,
|
|
|
|
+ attributes: nil)
|
|
|
|
+ } catch let error {
|
|
|
|
+ print("error creating filepath: \(error)")
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return storagePathUrl
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|