Add progress bar to uploads
This commit is contained in:
parent
898cb3f65b
commit
ae23766fe4
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F2073" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="8xC-Gn-SAo">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="8xC-Gn-SAo">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
|
@ -72,6 +72,10 @@
|
|||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JEW-rQ-Kb1">
|
||||
<rect key="frame" x="16" y="383" width="343" height="2"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
</progressView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
|
@ -84,6 +88,7 @@
|
|||
<outlet property="dcavTextField" destination="9YY-rV-nVu" id="RPZ-ov-oMp"/>
|
||||
<outlet property="imageView" destination="3Cc-7Y-DVl" id="CcV-Us-W0x"/>
|
||||
<outlet property="labell" destination="Wr7-lK-wSY" id="u97-bt-PHA"/>
|
||||
<outlet property="uploadProgressBar" destination="JEW-rQ-Kb1" id="zuQ-8e-GvG"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
|
|
|
@ -8,13 +8,14 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate {
|
||||
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate, URLSessionDelegate, URLSessionTaskDelegate, URLSessionDataDelegate {
|
||||
|
||||
@IBOutlet weak var labell: UILabel!
|
||||
@IBOutlet weak var imageView: UIImageView!
|
||||
var imagePickerController : UIImagePickerController!
|
||||
@IBOutlet weak var dcavTextField: UITextField!
|
||||
var responseString : String!
|
||||
@IBOutlet weak var uploadProgressBar: UIProgressView!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
@ -51,7 +52,6 @@ class ViewController: UIViewController, UINavigationControllerDelegate, UIImageP
|
|||
dcavTextField.text = path
|
||||
}
|
||||
|
||||
|
||||
@IBAction func onSaveButton(_ sender: Any) {
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,9 @@ class ViewController: UIViewController, UINavigationControllerDelegate, UIImageP
|
|||
|
||||
let request = generateRequest(user: username, pass: passphrase)
|
||||
|
||||
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
||||
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: OperationQueue.main)
|
||||
|
||||
let task = session.dataTask(with: request) { data, response, error in
|
||||
guard let data = data, error == nil else { // check for fundamental networking error
|
||||
print("error=\(String(describing: error))")
|
||||
return
|
||||
|
@ -89,8 +91,6 @@ class ViewController: UIViewController, UINavigationControllerDelegate, UIImageP
|
|||
task.resume()
|
||||
}
|
||||
|
||||
|
||||
|
||||
func generateBoundaryString() -> String {
|
||||
return "Boundary-\(NSUUID().uuidString)"
|
||||
}
|
||||
|
@ -129,5 +129,11 @@ class ViewController: UIViewController, UINavigationControllerDelegate, UIImageP
|
|||
|
||||
return request
|
||||
}
|
||||
|
||||
//MARK:Update progress bar
|
||||
func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
|
||||
uploadProgressBar.progress = Float(totalBytesSent) / Float(totalBytesExpectedToSend)
|
||||
print(String(describing: uploadProgressBar.progress))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user