Skip to content

Commit 4e8b2f4

Browse files
authored
Merge pull request #90 from tus/swift-development
2.1.0
2 parents 89360b7 + 590e8aa commit 4e8b2f4

21 files changed

+630
-219
lines changed

.DS_Store

-6 KB
Binary file not shown.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ DerivedData
1818
*.xcuserstate
1919
*.xcworkspace
2020
!default.xcworkspace
21+
.DS_Store
2122

2223
# CocoaPods
2324
#
@@ -26,3 +27,6 @@ DerivedData
2627
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
2728
#
2829
Pods/
30+
31+
# IntelliJ
32+
.idea/

Example/.DS_Store

-6 KB
Binary file not shown.

Example/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use_frameworks!
22

33
target 'TUSKit_Example' do
44
pod 'TUSKit', :path => '../'
5+
pod 'TLPhotoPicker'
56

67
target 'TUSKit_Tests' do
78
inherit! :search_paths

Example/Podfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ PODS:
1212
- FBSnapshotTestCase (~> 2.0)
1313
- Nimble (~> 7.0)
1414
- Quick (1.2.0)
15-
- TLPhotoPicker (2.0.11)
16-
- TUSKit (2.0.3.alpha):
17-
- TLPhotoPicker
15+
- TLPhotoPicker (2.1.3)
16+
- TUSKit (2.0.0)
1817

1918
DEPENDENCIES:
2019
- AppSpectorSDK
2120
- FBSnapshotTestCase (~> 2.1.4)
2221
- Nimble (~> 7.0)
2322
- Nimble-Snapshots (~> 6.3.0)
2423
- Quick (~> 1.2.0)
24+
- TLPhotoPicker
2525
- TUSKit (from `../`)
2626

2727
SPEC REPOS:
@@ -43,9 +43,9 @@ SPEC CHECKSUMS:
4343
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
4444
Nimble-Snapshots: f5459b5b091678dc942d03ec4741cacb58ba4a52
4545
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
46-
TLPhotoPicker: a5c339732b8326bb16cbb4e00ed01a86f2bfbbb3
47-
TUSKit: 23162a720b2e89c2cad7bc2397592bf8893cf64a
46+
TLPhotoPicker: 2c4a20d62952bd368edbf44d18476f663a718ada
47+
TUSKit: befb40e402aae1ee35a6b2b1edda26416bd0e473
4848

49-
PODFILE CHECKSUM: 572a5d87651b95d2aa1ecdf921075dfd78b37d95
49+
PODFILE CHECKSUM: 56e9b6c1fa8da25eda882f2eaba8707f765eb8e1
5050

51-
COCOAPODS: 1.9.1
51+
COCOAPODS: 1.10.1

Example/TUSKit/ViewController.swift

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,106 +10,113 @@ import UIKit
1010
import TUSKit
1111

1212
class ViewController: UIViewController, TUSDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
13-
13+
1414
let imagePicker = UIImagePickerController()
1515

1616
@IBOutlet weak var numberOfFilesLabel: UILabel!
1717
@IBOutlet weak var progressLabel: UILabel!
1818
@IBOutlet weak var progressBar: UIProgressView!
1919
@IBOutlet weak var numberOfFilesUploadingLabel: UILabel!
2020
@IBOutlet weak var numberOfFileUploadLabel: UILabel!
21-
21+
2222
var files: [URL] = []
2323
var numOfUploaded = 0
24-
24+
2525
override func viewDidLoad() {
2626
super.viewDidLoad()
2727
//Image picker setup for example.
2828
imagePicker.sourceType = .photoLibrary
2929
imagePicker.delegate = self
30-
30+
3131
//Set the deleagte of TUSClient
3232
TUSClient.shared.delegate = self
33-
34-
33+
34+
3535
// if let path = Bundle.main.path(forResource: "test", ofType:"mp4") {
3636
// let number = Int.random(in: 0 ..< 100) //TODO: Remove before release: this is only set so we can run multiple files while developer
3737
// let upload: TUSUpload = TUSUpload(withId: String(format: "%@%@", "video", String(number)), andFilePathURL: URL(fileURLWithPath: path), andFileType: ".mp4")
3838
// //Create or resume upload
3939
//
4040
// TUSClient.shared.createOrResume(forUpload: upload)
4141
// }
42-
42+
4343
}
44-
44+
4545
func updateLabel() {
4646
numberOfFilesLabel.text = "\(files.count) of files ready for upload"
4747
numberOfFilesUploadingLabel.text = "\(String(describing: TUSClient.shared.currentUploads!.count)) files uploading"
4848
numberOfFileUploadLabel.text = "\(numOfUploaded) files uploaded"
4949
}
50-
50+
5151
@IBAction func addFileAction(_ sender: Any) {
5252
present(imagePicker, animated: true, completion: nil)
5353
}
54-
54+
5555
@IBAction func uploadAction(_ sender: Any) {
56+
if (TUSClient.shared.status == TUSClientStaus.ready
57+
&& TUSClient.shared.currentUploads!.count > 0
58+
&& files.count <= 0) {
59+
TUSClient.shared.resumeAll()
60+
return;
61+
}
62+
5663
for file in files {
5764
let number = Int.random(in: 0 ..< 1000) //TODO: Remove before release: this is only set so we can run multiple files while developer
58-
65+
5966
//When you have a file, create an upload, and give it a Id.
60-
var fileData = try! Data(contentsOf: file)
61-
let upload: TUSUpload = TUSUpload(withId: String(number), andData: fileData, andFileType: "jpeg")
67+
let upload: TUSUpload = TUSUpload(withId: String(number), andFilePathURL: file, andFileType: ".jpeg")
6268
upload.metadata = ["hello": "world"]
6369
//Create or resume upload
6470
TUSClient.shared.createOrResume(forUpload: upload, withCustomHeaders: ["Header": "Value"])
6571
}
6672
updateLabel()
6773
}
68-
69-
74+
75+
7076
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
7177

7278
if #available(iOS 11.0, *) {
7379
guard let imageURL = info[.imageURL] else {
7480
return
7581
}
76-
82+
7783
files.append(imageURL as! URL)
7884
updateLabel()
7985
}
80-
86+
8187
dismiss(animated: true) {
8288
}
8389
}
8490
//
8591
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
8692
dismiss(animated: true, completion: nil)
8793
}
88-
94+
8995
//MARK: TUSClient Deleagte
90-
96+
9197
func TUSProgress(bytesUploaded uploaded: Int, bytesRemaining remaining: Int) {
92-
//
93-
print(uploaded)
94-
print(remaining)
98+
print("Global upload: \(uploaded)/\(remaining)");
9599
self.progressLabel.text = "\(uploaded)/\(remaining)"
96100
self.progressBar.progress = Float(uploaded) / Float(remaining)
97101
}
98-
102+
99103
func TUSProgress(forUpload upload: TUSUpload, bytesUploaded uploaded: Int, bytesRemaining remaining: Int) {
100-
//
101-
print(uploaded)
102-
print(remaining)
104+
print("Upload for: \(upload.id) \(uploaded)/\(remaining)");
103105
}
104-
106+
105107
func TUSSuccess(forUpload upload: TUSUpload) {
106108
print(upload.uploadLocationURL)
107109
TUSClient.shared.getFile(forUpload: upload)
108110
numOfUploaded = numOfUploaded + 1
109-
updateLabel()
111+
// Delay the update a second, because we will get the pending uploads
112+
// from TUS. After a upload has finished it may take some short amount of time after the
113+
// persistence layer has been updated.
114+
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
115+
self.updateLabel()
116+
}
110117
//
111118
}
112-
119+
113120
func TUSFailure(forUpload upload: TUSUpload?, withResponse response: TUSResponse?, andError error: Error?) {
114121
//
115122
if (response != nil) {

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,11 @@ The delegate method fire when a file stops (canceled, failure, or paused)
156156
```Swift
157157
func TUSFailure(TUSUpload, TUSResponse)
158158
```
159+
160+
# Contributors
161+
162+
<a href="https://github.com/tus/tuskit/graphs/contributors">
163+
<img src="https://contrib.rocks/image?repo=tus/tuskit" />
164+
</a>
165+
166+
Made with [contributors-img](https://contrib.rocks).

TUSKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TODO: Add long description of the pod here.
3030
s.source = { :git => 'https://github.com/tus/tus-ios-client.git', :tag => s.version.to_s }
3131
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
3232

33-
s.ios.deployment_target = '8.0'
33+
s.ios.deployment_target = '8.2'
3434
s.osx.deployment_target = '10.10'
3535

3636
s.source_files = 'TUSKit/Classes/**/*'

TUSKit/.DS_Store

-6 KB
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// TUSBackgroundMode.swift
3+
// TUSKit
4+
//
5+
// Created by Hanno Gödecke on 25.02.21.
6+
//
7+
8+
import Foundation
9+
10+
public enum TUSBackgroundMode: Int {
11+
/// This tries to upload everything that is in the queue
12+
/// even if the app goes into background. The problem is,
13+
/// that the background processing can be shut down, so
14+
/// the queue won't finish. In this case you need to
15+
/// resume the queue on your own when the app is started again.
16+
case PreferUploadQueue = 0
17+
/// This is the default. It means that it tries to finish
18+
/// the current upload task and then stop.
19+
/// This is prefered, as its more likely to finish one upload
20+
/// than the whole queue. Plus it is more battery friendly,
21+
/// as the app will spend less time processing in the background.
22+
case PreferFinishUpload = 1
23+
}

0 commit comments

Comments
 (0)