Skip to content

Commit 802ef4a

Browse files
authored
Merge pull request #372 from qiniu/develop
Develop to master
2 parents a119996 + 6fc1612 commit 802ef4a

File tree

26 files changed

+580
-106
lines changed

26 files changed

+580
-106
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#Demo
2+
DemoTestResource/
3+
14
# System
25
.DS_Store
36

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#Changelog
2+
## 8.0.4(2020-10-20)
3+
## 优化
4+
- 优化超时问题
5+
26
## 8.0.3(2020-09-23)
37
## 修正
48
- 修复内存峰值问题

Qiniu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Qiniu'
3-
s.version = '8.0.3'
3+
s.version = '8.0.4'
44
s.summary = 'Qiniu Resource Storage SDK for iOS and Mac'
55
s.homepage = 'https://github.com/qiniu/objc-sdk'
66
s.social_media_url = 'http://weibo.com/qiniutek'

QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
26F62ADDD5B6306E978C9A3F /* libPods-QiniuDemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */; };
1111
2B848FF719DFA7ECB394CA9F /* libPods-QiniuDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B9BC5A8D93F988C1240E05F /* libPods-QiniuDemo.a */; };
12+
318191AB2531516F00D18536 /* UploadResource.dmg in Resources */ = {isa = PBXBuildFile; fileRef = 318191AA2531516F00D18536 /* UploadResource.dmg */; };
1213
93D230241C86D7F700434F6D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230231C86D7F700434F6D /* main.m */; };
1314
93D230271C86D7F700434F6D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230261C86D7F700434F6D /* AppDelegate.m */; };
1415
93D2302A1C86D7F700434F6D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230291C86D7F700434F6D /* ViewController.m */; };
@@ -39,6 +40,8 @@
3940
/* Begin PBXFileReference section */
4041
14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuDemoTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4142
24EE530BBB100BED89B08A3D /* Pods-QiniuDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuDemo/Pods-QiniuDemo.release.xcconfig"; sourceTree = "<group>"; };
43+
318191AA2531516F00D18536 /* UploadResource.dmg */ = {isa = PBXFileReference; lastKnownFileType = file; path = UploadResource.dmg; sourceTree = "<group>"; };
44+
318191AF25315F3500D18536 /* Configure.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Configure.h; sourceTree = "<group>"; };
4245
6B9BC5A8D93F988C1240E05F /* libPods-QiniuDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4346
93D2301F1C86D7F700434F6D /* QiniuDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = QiniuDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
4447
93D230231C86D7F700434F6D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -88,6 +91,15 @@
8891
/* End PBXFrameworksBuildPhase section */
8992

9093
/* Begin PBXGroup section */
94+
318191A92531516F00D18536 /* DemoTestResource */ = {
95+
isa = PBXGroup;
96+
children = (
97+
318191AF25315F3500D18536 /* Configure.h */,
98+
318191AA2531516F00D18536 /* UploadResource.dmg */,
99+
);
100+
path = DemoTestResource;
101+
sourceTree = "<group>";
102+
};
91103
63D8EA8E5532E578D972E007 /* Pods */ = {
92104
isa = PBXGroup;
93105
children = (
@@ -133,6 +145,7 @@
133145
93D230211C86D7F700434F6D /* QiniuDemo */ = {
134146
isa = PBXGroup;
135147
children = (
148+
318191A92531516F00D18536 /* DemoTestResource */,
136149
93D230251C86D7F700434F6D /* AppDelegate.h */,
137150
93D230261C86D7F700434F6D /* AppDelegate.m */,
138151
93D230281C86D7F700434F6D /* ViewController.h */,
@@ -279,6 +292,7 @@
279292
buildActionMask = 2147483647;
280293
files = (
281294
93D230321C86D7F700434F6D /* LaunchScreen.storyboard in Resources */,
295+
318191AB2531516F00D18536 /* UploadResource.dmg in Resources */,
282296
93D2302F1C86D7F700434F6D /* Assets.xcassets in Resources */,
283297
93D2302D1C86D7F700434F6D /* Main.storyboard in Resources */,
284298
);

QiniuDemo/QiniuDemo/Base.lproj/Main.storyboard

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@
4949
<action selector="chooseAction:" destination="a0v-GO-7Qr" eventType="touchUpInside" id="tAj-mW-jxy"/>
5050
</connections>
5151
</button>
52-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Psn-X6-kmD">
52+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Psn-X6-kmD">
5353
<rect key="frame" x="70" y="662" width="274" height="50"/>
5454
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
5555
<constraints>
5656
<constraint firstAttribute="height" constant="50" id="pu0-Bk-3Gw"/>
5757
</constraints>
58-
<fontDescription key="fontDescription" type="system" pointSize="20"/>
5958
<state key="normal" title="上传">
6059
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
6160
</state>
61+
<state key="selected" title="取消上传"/>
6262
<connections>
6363
<action selector="uploadAction:" destination="a0v-GO-7Qr" eventType="touchUpInside" id="QAY-9o-VbD"/>
6464
</connections>

QiniuDemo/QiniuDemo/ViewController.m

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@
66
// Copyright © 2016年 Aaron. All rights reserved.
77
//
88

9+
#import "Configure.h" // 测试参数配置,暂时只有token,可删除
10+
911
#import "ViewController.h"
1012
#import "QNTransactionManager.h"
1113

14+
typedef NS_ENUM(NSInteger, UploadState){
15+
UploadStatePrepare,
16+
UploadStateUploading,
17+
UploadStateCancelling
18+
};
19+
1220
@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
1321

1422
@property (nonatomic, weak) IBOutlet UIButton* chooseBtn;
1523
@property (nonatomic, weak) IBOutlet UIButton* uploadBtn;
1624
@property (nonatomic, weak) IBOutlet UIImageView* preViewImage;
1725
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
1826

27+
@property (nonatomic, assign) UploadState uploadState;
1928
@property (nonatomic, strong) NSString *token;
2029
@property (nonatomic, strong) UIImage *pickImage;
2130

@@ -26,25 +35,56 @@ @implementation ViewController
2635
- (void)viewDidLoad {
2736
[super viewDidLoad];
2837
// Do any additional setup after loading the view, typically from a nib.
38+
[self changeUploadState:UploadStatePrepare];
2939
self.title = @"七牛云上传";
3040
}
3141

3242
- (IBAction)chooseAction:(id)sender {
3343
[self gotoImageLibrary];
3444
}
3545

36-
- (IBAction)uploadAction:(id)sender {
37-
if (self.pickImage == nil) {
38-
[self alertMessage:@"还未选择图片"];
46+
- (IBAction)uploadAction:(UIButton *)sender {
47+
if (self.uploadState == UploadStatePrepare) {
48+
49+
#ifdef YourToken
50+
NSString *path = [[NSBundle mainBundle] pathForResource:@"UploadResource.dmg" ofType:nil];
51+
[self uploadImageToQNFilePath:path];
52+
[self changeUploadState:UploadStateUploading];
53+
#else
54+
if (self.pickImage == nil) {
55+
[self alertMessage:@"还未选择图片"];
56+
} else {
57+
[self uploadImageToQNFilePath:[self getImagePath:self.pickImage]];
58+
[self changeUploadState:UploadStateUploading];
59+
}
60+
#endif
61+
3962
} else {
40-
[self uploadImageToQNFilePath:[self getImagePath:self.pickImage]];
63+
[self changeUploadState:UploadStateCancelling];
64+
}
65+
}
66+
67+
- (void)changeUploadState:(UploadState)uploadState{
68+
69+
self.uploadState = uploadState;
70+
if (uploadState == UploadStatePrepare) {
71+
[self.uploadBtn setTitle:@"上传" forState:UIControlStateNormal];
72+
self.uploadBtn.enabled = true;
73+
} else if (uploadState == UploadStateUploading) {
74+
[self.uploadBtn setTitle:@"取消上传" forState:UIControlStateNormal];
75+
self.uploadBtn.enabled = true;
76+
} else {
77+
[self.uploadBtn setTitle:@"取消上传" forState:UIControlStateNormal];
78+
self.uploadBtn.enabled = false;
4179
}
4280
}
4381

4482
- (void)uploadImageToQNFilePath:(NSString *)filePath {
45-
self.token = @"你的token";
83+
84+
self.token = YourToken;
4685
QNConfiguration *configuration = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
4786
builder.useConcurrentResumeUpload = true;
87+
builder.recorder = [QNFileRecorder fileRecorderWithFolder:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] error:nil];
4888
}];
4989
QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:configuration];
5090

@@ -55,11 +95,16 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath {
5595
}
5696
params:nil
5797
checkCrc:NO
58-
cancellationSignal:nil];
59-
[upManager putFile:filePath key:nil token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
98+
cancellationSignal:^BOOL{
99+
return weakSelf.uploadState == UploadStateCancelling;
100+
}];
101+
102+
[upManager putFile:filePath key:@"DemoResource" token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
60103
NSLog(@"info ===== %@", info);
61104
NSLog(@"resp ===== %@", resp);
62-
[self alertMessage:info.message];
105+
106+
[weakSelf changeUploadState:UploadStatePrepare];
107+
[weakSelf alertMessage:info.message];
63108
}
64109
option:uploadOption];
65110
}

QiniuSDK.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
31C2EEEC242DEF6A00713A33 /* QNUtilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */; };
110110
31C2EEED242DEF6A00713A33 /* QNUtilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */; };
111111
31C6E68824ECC75700633629 /* NSData+QNGZip.m in Sources */ = {isa = PBXBuildFile; fileRef = 31259E3124E3D02C00CF7531 /* NSData+QNGZip.m */; };
112+
31D8446A254017BD005C0222 /* QNErrorCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 31D84468254017BD005C0222 /* QNErrorCode.h */; };
113+
31D8446B254017BD005C0222 /* QNErrorCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 31D84469254017BD005C0222 /* QNErrorCode.m */; };
114+
31D8446C254017BD005C0222 /* QNErrorCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 31D84469254017BD005C0222 /* QNErrorCode.m */; };
112115
31DD31D624971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31DD31D524971BD7004BFDDE /* QNUploadFileNameTest.m */; };
113116
31DD31D724971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31DD31D524971BD7004BFDDE /* QNUploadFileNameTest.m */; };
114117
31E6B30124D8159F0097527D /* QNDnsCacheInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 31C2EEC6242CC52600713A33 /* QNDnsCacheInfo.m */; };
@@ -318,6 +321,8 @@
318321
31C2EEE1242DE86300713A33 /* QNUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUtils.h; sourceTree = "<group>"; };
319322
31C2EEE2242DE86300713A33 /* QNUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUtils.m; sourceTree = "<group>"; };
320323
31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUtilTest.m; sourceTree = "<group>"; };
324+
31D84468254017BD005C0222 /* QNErrorCode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNErrorCode.h; sourceTree = "<group>"; };
325+
31D84469254017BD005C0222 /* QNErrorCode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNErrorCode.m; sourceTree = "<group>"; };
321326
31DD31D524971BD7004BFDDE /* QNUploadFileNameTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUploadFileNameTest.m; sourceTree = "<group>"; };
322327
31F5537D2456F2F2000B66AD /* QNUrlSafeBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNUrlSafeBase64.m; sourceTree = "<group>"; };
323328
31F5537E2456F2F2000B66AD /* QNPHAssetResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNPHAssetResource.h; sourceTree = "<group>"; };
@@ -718,6 +723,8 @@
718723
31494470244851DE00386F16 /* QNAutoZone.m */,
719724
31494474244852BA00386F16 /* QNFixedZone.h */,
720725
31494475244852BA00386F16 /* QNFixedZone.m */,
726+
31D84468254017BD005C0222 /* QNErrorCode.h */,
727+
31D84469254017BD005C0222 /* QNErrorCode.m */,
721728
);
722729
path = Common;
723730
sourceTree = "<group>";
@@ -846,6 +853,7 @@
846853
31494476244852BA00386F16 /* QNFixedZone.h in Headers */,
847854
31494471244851DE00386F16 /* QNAutoZone.h in Headers */,
848855
31C2EECC242CC52600713A33 /* QNDnsCacheFile.h in Headers */,
856+
31D8446A254017BD005C0222 /* QNErrorCode.h in Headers */,
849857
31F553D024597182000B66AD /* QNHttpSingleRequest.h in Headers */,
850858
CC2513C42455C141003F4C65 /* QNTempFile.h in Headers */,
851859
3149A1D324626B3100A2A15B /* QNUploadSystemClient.h in Headers */,
@@ -1154,6 +1162,7 @@
11541162
DFA9B64A19E0018800A15FD1 /* QNUploadOption.m in Sources */,
11551163
CC3F322422C0CCDF00F23681 /* QNUploadInfoReporter.m in Sources */,
11561164
DF2CDE6A19DAC6A400CE01FB /* QNUploadManager.m in Sources */,
1165+
31D8446B254017BD005C0222 /* QNErrorCode.m in Sources */,
11571166
3149A1DD2462A57400A2A15B /* QNUploadDomainRegion.m in Sources */,
11581167
31C2EEE4242DE86300713A33 /* QNUtils.m in Sources */,
11591168
31FD0920248662F900217848 /* QNUploadServerFreezeManager.m in Sources */,
@@ -1221,6 +1230,7 @@
12211230
31A18421246BD988001D6EEE /* QNUploadRequestInfo.m in Sources */,
12221231
31F553CD24596C3D000B66AD /* QNHttpRegionRequest.m in Sources */,
12231232
31F553B72457D2FF000B66AD /* QNSystem.m in Sources */,
1233+
31D8446C254017BD005C0222 /* QNErrorCode.m in Sources */,
12241234
31E6B30124D8159F0097527D /* QNDnsCacheInfo.m in Sources */,
12251235
CC2513B8245423C3003F4C65 /* QNConcurrentResumeUpload.m in Sources */,
12261236
31F553C22457FFB0000B66AD /* QNPipeline.m in Sources */,

QiniuSDK/Collect/QNReportItem.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ - (NSString *)requestReportErrorType{
116116
errorType = @"parse_error";
117117
} else if (self.statusCode == -1007 || self.statusCode == -1010 || self.statusCode == kQNMaliciousResponseError){
118118
errorType = @"malicious_response";
119+
} else if (self.statusCode > -1130 && self.statusCode <= -1100){
120+
errorType = @"unexpected_syscall_error";
119121
} else if (self.statusCode == kQNRequestCancelled
120-
|| self.statusCode == NSURLErrorCancelled){
122+
|| self.statusCode == NSURLErrorCancelled){
121123
errorType = @"user_canceled";
122124
} else {
123125
errorType = @"unknown_error";

QiniuSDK/Common/QNErrorCode.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// QNErrorCode.h
3+
// QiniuSDK
4+
//
5+
// Created by yangsen on 2020/10/21.
6+
// Copyright © 2020 Qiniu. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
/**
12+
* 中途取消的状态码
13+
*/
14+
extern const int kQNRequestCancelled;
15+
16+
/**
17+
* 网络错误状态码
18+
*/
19+
extern const int kQNNetworkError;
20+
21+
/**
22+
* 错误参数状态码
23+
*/
24+
extern const int kQNInvalidArgument;
25+
26+
/**
27+
* 0 字节文件或数据
28+
*/
29+
extern const int kQNZeroDataSize;
30+
31+
/**
32+
* 错误token状态码
33+
*/
34+
extern const int kQNInvalidToken;
35+
36+
/**
37+
* 读取文件错误状态码
38+
*/
39+
extern const int kQNFileError;
40+
41+
/**
42+
* 本地 I/O 错误
43+
*/
44+
extern const int kQNLocalIOError;
45+
46+
/**
47+
* ⽤户劫持错误 错误
48+
*/
49+
extern const int kQNMaliciousResponseError;
50+
51+
/**
52+
* 非预期的系统调用 错误
53+
*/
54+
extern const int kQNUnexpectedSysCallError;

QiniuSDK/Common/QNErrorCode.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// QNErrorCode.m
3+
// QiniuSDK
4+
//
5+
// Created by yangsen on 2020/10/21.
6+
// Copyright © 2020 Qiniu. All rights reserved.
7+
//
8+
9+
#import "QNErrorCode.h"
10+
11+
const int kQNZeroDataSize = -6;
12+
const int kQNInvalidToken = -5;
13+
const int kQNFileError = -4;
14+
const int kQNInvalidArgument = -3;
15+
const int kQNRequestCancelled = -2;
16+
const int kQNNetworkError = -1;
17+
const int kQNLocalIOError = -7;
18+
const int kQNMaliciousResponseError = -8;
19+
const int kQNUnexpectedSysCallError = -10;

0 commit comments

Comments
 (0)