Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Demo
DemoTestResource/

# System
.DS_Store

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#Changelog
## 8.0.4(2020-10-20)
## 优化
- 优化超时问题

## 8.0.3(2020-09-23)
## 修正
- 修复内存峰值问题
Expand Down
2 changes: 1 addition & 1 deletion Qiniu.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Qiniu'
s.version = '8.0.3'
s.version = '8.0.4'
s.summary = 'Qiniu Resource Storage SDK for iOS and Mac'
s.homepage = 'https://github.com/qiniu/objc-sdk'
s.social_media_url = 'http://weibo.com/qiniutek'
Expand Down
14 changes: 14 additions & 0 deletions QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
26F62ADDD5B6306E978C9A3F /* libPods-QiniuDemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */; };
2B848FF719DFA7ECB394CA9F /* libPods-QiniuDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B9BC5A8D93F988C1240E05F /* libPods-QiniuDemo.a */; };
318191AB2531516F00D18536 /* UploadResource.dmg in Resources */ = {isa = PBXBuildFile; fileRef = 318191AA2531516F00D18536 /* UploadResource.dmg */; };
93D230241C86D7F700434F6D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230231C86D7F700434F6D /* main.m */; };
93D230271C86D7F700434F6D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230261C86D7F700434F6D /* AppDelegate.m */; };
93D2302A1C86D7F700434F6D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230291C86D7F700434F6D /* ViewController.m */; };
Expand Down Expand Up @@ -39,6 +40,8 @@
/* Begin PBXFileReference section */
14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuDemoTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
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>"; };
318191AA2531516F00D18536 /* UploadResource.dmg */ = {isa = PBXFileReference; lastKnownFileType = file; path = UploadResource.dmg; sourceTree = "<group>"; };
318191AF25315F3500D18536 /* Configure.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Configure.h; sourceTree = "<group>"; };
6B9BC5A8D93F988C1240E05F /* libPods-QiniuDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
93D2301F1C86D7F700434F6D /* QiniuDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = QiniuDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
93D230231C86D7F700434F6D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,6 +91,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
318191A92531516F00D18536 /* DemoTestResource */ = {
isa = PBXGroup;
children = (
318191AF25315F3500D18536 /* Configure.h */,
318191AA2531516F00D18536 /* UploadResource.dmg */,
);
path = DemoTestResource;
sourceTree = "<group>";
};
63D8EA8E5532E578D972E007 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -133,6 +145,7 @@
93D230211C86D7F700434F6D /* QiniuDemo */ = {
isa = PBXGroup;
children = (
318191A92531516F00D18536 /* DemoTestResource */,
93D230251C86D7F700434F6D /* AppDelegate.h */,
93D230261C86D7F700434F6D /* AppDelegate.m */,
93D230281C86D7F700434F6D /* ViewController.h */,
Expand Down Expand Up @@ -279,6 +292,7 @@
buildActionMask = 2147483647;
files = (
93D230321C86D7F700434F6D /* LaunchScreen.storyboard in Resources */,
318191AB2531516F00D18536 /* UploadResource.dmg in Resources */,
93D2302F1C86D7F700434F6D /* Assets.xcassets in Resources */,
93D2302D1C86D7F700434F6D /* Main.storyboard in Resources */,
);
Expand Down
4 changes: 2 additions & 2 deletions QiniuDemo/QiniuDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@
<action selector="chooseAction:" destination="a0v-GO-7Qr" eventType="touchUpInside" id="tAj-mW-jxy"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Psn-X6-kmD">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Psn-X6-kmD">
<rect key="frame" x="70" y="662" width="274" height="50"/>
<color key="backgroundColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="pu0-Bk-3Gw"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<state key="normal" title="上传">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<state key="selected" title="取消上传"/>
<connections>
<action selector="uploadAction:" destination="a0v-GO-7Qr" eventType="touchUpInside" id="QAY-9o-VbD"/>
</connections>
Expand Down
61 changes: 53 additions & 8 deletions QiniuDemo/QiniuDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@
// Copyright © 2016年 Aaron. All rights reserved.
//

#import "Configure.h" // 测试参数配置,暂时只有token,可删除

#import "ViewController.h"
#import "QNTransactionManager.h"

typedef NS_ENUM(NSInteger, UploadState){
UploadStatePrepare,
UploadStateUploading,
UploadStateCancelling
};

@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (nonatomic, weak) IBOutlet UIButton* chooseBtn;
@property (nonatomic, weak) IBOutlet UIButton* uploadBtn;
@property (nonatomic, weak) IBOutlet UIImageView* preViewImage;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;

@property (nonatomic, assign) UploadState uploadState;
@property (nonatomic, strong) NSString *token;
@property (nonatomic, strong) UIImage *pickImage;

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

- (IBAction)chooseAction:(id)sender {
[self gotoImageLibrary];
}

- (IBAction)uploadAction:(id)sender {
if (self.pickImage == nil) {
[self alertMessage:@"还未选择图片"];
- (IBAction)uploadAction:(UIButton *)sender {
if (self.uploadState == UploadStatePrepare) {

#ifdef YourToken
NSString *path = [[NSBundle mainBundle] pathForResource:@"UploadResource.dmg" ofType:nil];
[self uploadImageToQNFilePath:path];
[self changeUploadState:UploadStateUploading];
#else
if (self.pickImage == nil) {
[self alertMessage:@"还未选择图片"];
} else {
[self uploadImageToQNFilePath:[self getImagePath:self.pickImage]];
[self changeUploadState:UploadStateUploading];
}
#endif

} else {
[self uploadImageToQNFilePath:[self getImagePath:self.pickImage]];
[self changeUploadState:UploadStateCancelling];
}
}

- (void)changeUploadState:(UploadState)uploadState{

self.uploadState = uploadState;
if (uploadState == UploadStatePrepare) {
[self.uploadBtn setTitle:@"上传" forState:UIControlStateNormal];
self.uploadBtn.enabled = true;
} else if (uploadState == UploadStateUploading) {
[self.uploadBtn setTitle:@"取消上传" forState:UIControlStateNormal];
self.uploadBtn.enabled = true;
} else {
[self.uploadBtn setTitle:@"取消上传" forState:UIControlStateNormal];
self.uploadBtn.enabled = false;
}
}

- (void)uploadImageToQNFilePath:(NSString *)filePath {
self.token = @"你的token";

self.token = YourToken;
QNConfiguration *configuration = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
builder.useConcurrentResumeUpload = true;
builder.recorder = [QNFileRecorder fileRecorderWithFolder:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] error:nil];
}];
QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:configuration];

Expand All @@ -55,11 +95,16 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath {
}
params:nil
checkCrc:NO
cancellationSignal:nil];
[upManager putFile:filePath key:nil token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
cancellationSignal:^BOOL{
return weakSelf.uploadState == UploadStateCancelling;
}];

[upManager putFile:filePath key:@"DemoResource" token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
NSLog(@"info ===== %@", info);
NSLog(@"resp ===== %@", resp);
[self alertMessage:info.message];

[weakSelf changeUploadState:UploadStatePrepare];
[weakSelf alertMessage:info.message];
}
option:uploadOption];
}
Expand Down
10 changes: 10 additions & 0 deletions QiniuSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
31C2EEEC242DEF6A00713A33 /* QNUtilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */; };
31C2EEED242DEF6A00713A33 /* QNUtilTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */; };
31C6E68824ECC75700633629 /* NSData+QNGZip.m in Sources */ = {isa = PBXBuildFile; fileRef = 31259E3124E3D02C00CF7531 /* NSData+QNGZip.m */; };
31D8446A254017BD005C0222 /* QNErrorCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 31D84468254017BD005C0222 /* QNErrorCode.h */; };
31D8446B254017BD005C0222 /* QNErrorCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 31D84469254017BD005C0222 /* QNErrorCode.m */; };
31D8446C254017BD005C0222 /* QNErrorCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 31D84469254017BD005C0222 /* QNErrorCode.m */; };
31DD31D624971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31DD31D524971BD7004BFDDE /* QNUploadFileNameTest.m */; };
31DD31D724971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 31DD31D524971BD7004BFDDE /* QNUploadFileNameTest.m */; };
31E6B30124D8159F0097527D /* QNDnsCacheInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 31C2EEC6242CC52600713A33 /* QNDnsCacheInfo.m */; };
Expand Down Expand Up @@ -318,6 +321,8 @@
31C2EEE1242DE86300713A33 /* QNUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUtils.h; sourceTree = "<group>"; };
31C2EEE2242DE86300713A33 /* QNUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUtils.m; sourceTree = "<group>"; };
31C2EEEB242DEF6A00713A33 /* QNUtilTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUtilTest.m; sourceTree = "<group>"; };
31D84468254017BD005C0222 /* QNErrorCode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNErrorCode.h; sourceTree = "<group>"; };
31D84469254017BD005C0222 /* QNErrorCode.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNErrorCode.m; sourceTree = "<group>"; };
31DD31D524971BD7004BFDDE /* QNUploadFileNameTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUploadFileNameTest.m; sourceTree = "<group>"; };
31F5537D2456F2F2000B66AD /* QNUrlSafeBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNUrlSafeBase64.m; sourceTree = "<group>"; };
31F5537E2456F2F2000B66AD /* QNPHAssetResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNPHAssetResource.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -718,6 +723,8 @@
31494470244851DE00386F16 /* QNAutoZone.m */,
31494474244852BA00386F16 /* QNFixedZone.h */,
31494475244852BA00386F16 /* QNFixedZone.m */,
31D84468254017BD005C0222 /* QNErrorCode.h */,
31D84469254017BD005C0222 /* QNErrorCode.m */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -846,6 +853,7 @@
31494476244852BA00386F16 /* QNFixedZone.h in Headers */,
31494471244851DE00386F16 /* QNAutoZone.h in Headers */,
31C2EECC242CC52600713A33 /* QNDnsCacheFile.h in Headers */,
31D8446A254017BD005C0222 /* QNErrorCode.h in Headers */,
31F553D024597182000B66AD /* QNHttpSingleRequest.h in Headers */,
CC2513C42455C141003F4C65 /* QNTempFile.h in Headers */,
3149A1D324626B3100A2A15B /* QNUploadSystemClient.h in Headers */,
Expand Down Expand Up @@ -1154,6 +1162,7 @@
DFA9B64A19E0018800A15FD1 /* QNUploadOption.m in Sources */,
CC3F322422C0CCDF00F23681 /* QNUploadInfoReporter.m in Sources */,
DF2CDE6A19DAC6A400CE01FB /* QNUploadManager.m in Sources */,
31D8446B254017BD005C0222 /* QNErrorCode.m in Sources */,
3149A1DD2462A57400A2A15B /* QNUploadDomainRegion.m in Sources */,
31C2EEE4242DE86300713A33 /* QNUtils.m in Sources */,
31FD0920248662F900217848 /* QNUploadServerFreezeManager.m in Sources */,
Expand Down Expand Up @@ -1221,6 +1230,7 @@
31A18421246BD988001D6EEE /* QNUploadRequestInfo.m in Sources */,
31F553CD24596C3D000B66AD /* QNHttpRegionRequest.m in Sources */,
31F553B72457D2FF000B66AD /* QNSystem.m in Sources */,
31D8446C254017BD005C0222 /* QNErrorCode.m in Sources */,
31E6B30124D8159F0097527D /* QNDnsCacheInfo.m in Sources */,
CC2513B8245423C3003F4C65 /* QNConcurrentResumeUpload.m in Sources */,
31F553C22457FFB0000B66AD /* QNPipeline.m in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion QiniuSDK/Collect/QNReportItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ - (NSString *)requestReportErrorType{
errorType = @"parse_error";
} else if (self.statusCode == -1007 || self.statusCode == -1010 || self.statusCode == kQNMaliciousResponseError){
errorType = @"malicious_response";
} else if (self.statusCode > -1130 && self.statusCode <= -1100){
errorType = @"unexpected_syscall_error";
} else if (self.statusCode == kQNRequestCancelled
|| self.statusCode == NSURLErrorCancelled){
|| self.statusCode == NSURLErrorCancelled){
errorType = @"user_canceled";
} else {
errorType = @"unknown_error";
Expand Down
54 changes: 54 additions & 0 deletions QiniuSDK/Common/QNErrorCode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// QNErrorCode.h
// QiniuSDK
//
// Created by yangsen on 2020/10/21.
// Copyright © 2020 Qiniu. All rights reserved.
//

#import <Foundation/Foundation.h>

/**
* 中途取消的状态码
*/
extern const int kQNRequestCancelled;

/**
* 网络错误状态码
*/
extern const int kQNNetworkError;

/**
* 错误参数状态码
*/
extern const int kQNInvalidArgument;

/**
* 0 字节文件或数据
*/
extern const int kQNZeroDataSize;

/**
* 错误token状态码
*/
extern const int kQNInvalidToken;

/**
* 读取文件错误状态码
*/
extern const int kQNFileError;

/**
* 本地 I/O 错误
*/
extern const int kQNLocalIOError;

/**
* ⽤户劫持错误 错误
*/
extern const int kQNMaliciousResponseError;

/**
* 非预期的系统调用 错误
*/
extern const int kQNUnexpectedSysCallError;
19 changes: 19 additions & 0 deletions QiniuSDK/Common/QNErrorCode.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// QNErrorCode.m
// QiniuSDK
//
// Created by yangsen on 2020/10/21.
// Copyright © 2020 Qiniu. All rights reserved.
//

#import "QNErrorCode.h"

const int kQNZeroDataSize = -6;
const int kQNInvalidToken = -5;
const int kQNFileError = -4;
const int kQNInvalidArgument = -3;
const int kQNRequestCancelled = -2;
const int kQNNetworkError = -1;
const int kQNLocalIOError = -7;
const int kQNMaliciousResponseError = -8;
const int kQNUnexpectedSysCallError = -10;
46 changes: 5 additions & 41 deletions QiniuSDK/Http/QNResponseInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,7 @@
//

#import "QNUploadRequestMetrics.h"

/**
* 中途取消的状态码
*/
extern const int kQNRequestCancelled;

/**
* 网络错误状态码
*/
extern const int kQNNetworkError;

/**
* 错误参数状态码
*/
extern const int kQNInvalidArgument;

/**
* 0 字节文件或数据
*/
extern const int kQNZeroDataSize;

/**
* 错误token状态码
*/
extern const int kQNInvalidToken;

/**
* 读取文件错误状态码
*/
extern const int kQNFileError;

/**
* 本地 I/O 错误
*/
extern const int kQNLocalIOError;

/**
* ⽤户劫持错误 错误
*/
extern const int kQNMaliciousResponseError;

#import "QNErrorCode.h"

/**
* 上传完成后返回的状态信息
Expand Down Expand Up @@ -88,6 +48,10 @@ extern const int kQNMaliciousResponseError;
@property (nonatomic, readonly) BOOL couldHostRetry;
/// 单个Region是否可以再次重试
@property (nonatomic, readonly) BOOL couldRegionRetry;
/// 当前host是否可达
@property (nonatomic, readonly) BOOL canConnectToHost;
/// 当前host是否可用
@property (nonatomic, readonly) BOOL isHostUnavailable;
/// 是否为 七牛响应
@property (nonatomic, readonly, getter=isNotQiniu) BOOL notQiniu;

Expand Down
Loading