Bladeren bron

update upload & download

kevin 2 jaren geleden
bovenliggende
commit
23373d3bb2

+ 4 - 1
appbuilder-ios/NexilisLite/NexilisLite/Source/Download.swift

@@ -59,7 +59,10 @@ public class Download {
 //            let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory, in: .userDomainMask, options: [.removePreviousFile, .createIntermediateDirectories])
             let downloadRequest = AF.download(fullURL)
             .downloadProgress(queue: downloadBufferQueue) { progress in
-                completion(filename,progress.fractionCompleted*100)
+                let frac = progress.fractionCompleted*100
+                if frac != 100.0 {
+                    completion(filename,frac)
+                }
             }
             .responseData { result in
                 if let successResponse = result.value {

+ 14 - 4
appbuilder-ios/NexilisLite/NexilisLite/Source/Network.swift

@@ -194,7 +194,8 @@ public class Network {
     
     public func uploadHTTP(_ endUrl: String, files: [URL] = [], filename: [String] = [], parameters: [String : Any] = [:], completion: @escaping (Bool, Double, [String:Any]?)->()) -> UploadRequest {
         
-        var filesIn = files
+        var filesIn = [URL]()
+        filesIn.append(contentsOf: files)
         
         if !filename.isEmpty {
             do {
@@ -220,23 +221,32 @@ public class Network {
             
             for i in 0..<filesIn.count {
                 multipartFormData.append(filesIn[i], withName: "file\(i+1)", fileName: filesIn[i].lastPathComponent, mimeType: "application/octet-stream")
+                Nexilis.putUploadFile(forKey: filesIn[i].lastPathComponent, uploader: self)
                 //print(multipartFormData)
             }
             
         }, to: endUrl)
         .responseJSON { result in
             if let successResponse = result.value as? [String:Any] {
-                //print("Response success")
+                print("Response success")
+                for url in filesIn {
+                    Nexilis.removeUploadFile(forKey: url.lastPathComponent)
+                }
                 completion(true,100,successResponse)
+                
             }
             else {
                 let statusCode = result.response?.statusCode
-                //print("Response fail: \(statusCode)")
+                print("Response fail: \(statusCode)")
                 completion(false,0,nil)
             }
         }
         .uploadProgress { progress in
-            completion(!progress.isCancelled,progress.fractionCompleted*100,nil)
+            print("Response progress: \(progress.fractionCompleted*100)")
+            let frac = progress.fractionCompleted*100
+            if frac != 100.0 {
+                completion(!progress.isCancelled,frac,nil)
+            }
         }
         
         return uploadRequest

+ 1 - 1
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Chat/EditorGroup.swift

@@ -1543,7 +1543,7 @@ public class EditorGroup: UIViewController {
                 }
             }
             let indexPathFirst = tableChatView.indexPathsForVisibleRows?.first
-            if indexPathFirst != nil && listViewOnSection.count != 0 && listViewOnSection.count - 1 <= indexPathFirst!.section{
+            if indexPathFirst != nil && listViewOnSection.count != 0 && listViewOnSection.count - 1 >= indexPathFirst!.section {
                 let headerView = listViewOnSection[indexPathFirst!.section]
                 if headerView.isHidden {
                     headerView.isHidden = false

+ 1 - 1
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Chat/EditorPersonal.swift

@@ -2824,7 +2824,7 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
                 }
             }
             let indexPathFirst = tableChatView.indexPathsForVisibleRows?.first
-            if indexPathFirst != nil && listViewOnSection.count != 0 && listViewOnSection.count - 1 <= indexPathFirst!.section{
+            if indexPathFirst != nil && listViewOnSection.count != 0 && listViewOnSection.count - 1 >= indexPathFirst!.section {
                 let headerView = listViewOnSection[indexPathFirst!.section]
                 if headerView.isHidden {
                     headerView.isHidden = false