Skip to content

Commit 6999cb4

Browse files
authored
Merge pull request #401 from YangSen-qn/master
handle sometimes PHAssert upload fail
2 parents 345defa + 23d18c1 commit 6999cb4

File tree

15 files changed

+72
-39
lines changed

15 files changed

+72
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#Changelog
2+
## 8.3.2(2021-09-3)
3+
## 优化
4+
- 处理 PHAssert 偶现上传失败问题
5+
26
## 8.3.1(2021-08-12)
37
## 优化
48
- 对 DNS 域名预解析缓存增加缓存有效期,默认 10 分钟,支持手动修改有效期时长,kQNGlobalConfiguration.dnsCacheMaxTTL 单位为 s

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.3.1'
3+
s.version = '8.3.2'
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/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source 'https://github.com/CocoaPods/Specs.git'
22

33
target "QiniuDemo" do
4-
platform :ios, "7.0"
4+
platform :ios, "10.0"
55

66
# pod 'Qiniu', '~> 8.1.1'
77
pod 'Qiniu',:path => '../'

QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@
553553
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
554554
PRODUCT_BUNDLE_IDENTIFIER = com.qiniu.QiniuDemo;
555555
PRODUCT_NAME = "$(TARGET_NAME)";
556+
STRIP_SWIFT_SYMBOLS = YES;
556557
SUPPORTS_MACCATALYST = YES;
557558
};
558559
name = Debug;
@@ -569,6 +570,7 @@
569570
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
570571
PRODUCT_BUNDLE_IDENTIFIER = com.qiniu.QiniuDemo;
571572
PRODUCT_NAME = "$(TARGET_NAME)";
573+
STRIP_SWIFT_SYMBOLS = YES;
572574
SUPPORTS_MACCATALYST = YES;
573575
};
574576
name = Release;

QiniuDemo/QiniuDemo/ViewController.m

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,27 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath {
124124
// }
125125
// option:uploadOption];
126126

127-
long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil] fileSize];
128-
NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:filePath];
129-
[upManager putInputStream:stream sourceId:filePath.lastPathComponent size:fileSize fileName:filePath.lastPathComponent key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
130-
NSLog(@"info ===== %@", info);
131-
NSLog(@"resp ===== %@", resp);
132-
133-
[weakSelf changeUploadState:UploadStatePrepare];
134-
[weakSelf alertMessage:info.message];
135-
} option:uploadOption];
136-
137-
// NSURL *url = [NSURL fileURLWithPath:filePath];
138-
// PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
139-
// PHAsset *asset = [self getPHAssert];
140-
// [upManager putPHAsset:asset key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
127+
// long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil] fileSize];
128+
// NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:filePath];
129+
// [upManager putInputStream:stream sourceId:filePath.lastPathComponent size:fileSize fileName:filePath.lastPathComponent key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
141130
// NSLog(@"info ===== %@", info);
142131
// NSLog(@"resp ===== %@", resp);
143132
//
144133
// [weakSelf changeUploadState:UploadStatePrepare];
145134
// [weakSelf alertMessage:info.message];
146-
// }
147-
// option:uploadOption];
135+
// } option:uploadOption];
136+
137+
NSURL *url = [NSURL fileURLWithPath:filePath];
138+
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
139+
PHAsset *asset = [self getPHAssert];
140+
[upManager putPHAsset:asset key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
141+
NSLog(@"info ===== %@", info);
142+
NSLog(@"resp ===== %@", resp);
143+
144+
[weakSelf changeUploadState:UploadStatePrepare];
145+
[weakSelf alertMessage:info.message];
146+
}
147+
option:uploadOption];
148148
}
149149

150150
- (PHAsset *)getPHAssert {

QiniuSDK/Storage/QNUploadInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
6464
/// @param dataSize 读取数据大小
6565
/// @param dataOffset 数据偏移量
6666
/// @param error 读取时的错误信息
67-
- (NSData *)readData:(NSInteger)dataSize dataOffset:(long)dataOffset error:(NSError **)error;
67+
- (NSData *)readData:(NSInteger)dataSize dataOffset:(long long)dataOffset error:(NSError **)error;
6868

6969
/// 关闭流
7070
- (void)close;

QiniuSDK/Storage/QNUploadInfo.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@interface QNUploadInfo()
1313

1414
@property(nonatomic, copy)NSString *sourceId;
15-
@property(nonatomic, assign)long sourceSize;
15+
@property(nonatomic, assign)long long sourceSize;
1616
@property(nonatomic, copy)NSString *fileName;
1717

1818
@property(nonatomic, strong)id <QNUploadSource> source;
@@ -58,7 +58,7 @@ - (NSString *)getSourceId {
5858
return [self.source getId];
5959
}
6060

61-
- (long)getSourceSize {
61+
- (long long)getSourceSize {
6262
return [self.source getSize];
6363
}
6464

@@ -91,7 +91,7 @@ - (void)clearUploadState {
9191
- (void)checkInfoStateAndUpdate {
9292
}
9393

94-
- (NSData *)readData:(NSInteger)dataSize dataOffset:(long)dataOffset error:(NSError **)error {
94+
- (NSData *)readData:(NSInteger)dataSize dataOffset:(long long)dataOffset error:(NSError **)error {
9595
if (!self.source) {
9696
*error = [NSError errorWithDomain:NSStreamSOCKSErrorDomain code:kQNLocalIOError userInfo:@{NSLocalizedDescriptionKey : @"file is not exist"}];
9797
return nil;

QiniuSDK/Storage/QNUploadInfoV1.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ - (QNUploadBlock *)nextUploadBlock:(NSError **)error {
174174
}
175175

176176
// 从资源中读取新的 block 进行上传
177-
long blockOffset = 0;
177+
long long blockOffset = 0;
178178
if (self.blockList.count > 0) {
179179
QNUploadBlock *lastBlock = self.blockList[self.blockList.count - 1];
180-
blockOffset = lastBlock.offset + lastBlock.size;
180+
blockOffset = lastBlock.offset + (long long)(lastBlock.size);
181181
}
182182

183183
block = [[QNUploadBlock alloc] initWithOffset:blockOffset blockSize:kBlockSize dataSize:self.dataSize index:self.blockList.count];

QiniuSDK/Storage/QNUploadSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
5151
*
5252
* @return 资源大小
5353
*/
54-
- (long)getSize;
54+
- (long long)getSize;
5555

5656
/**
5757
* 读取数据

QiniuSDK/Storage/QNUploadSourceFile.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ - (nonnull NSString *)getFileName {
3838
return [[self.file path] lastPathComponent];
3939
}
4040

41-
- (long)getSize {
41+
- (long long)getSize {
4242
return [self.file size];
4343
}
4444

0 commit comments

Comments
 (0)