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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#Changelog
## 8.3.2(2021-09-3)
## 优化
- 处理 PHAssert 偶现上传失败问题

## 8.3.1(2021-08-12)
## 优化
- 对 DNS 域名预解析缓存增加缓存有效期,默认 10 分钟,支持手动修改有效期时长,kQNGlobalConfiguration.dnsCacheMaxTTL 单位为 s
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.3.1'
s.version = '8.3.2'
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
2 changes: 1 addition & 1 deletion QiniuDemo/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://github.com/CocoaPods/Specs.git'

target "QiniuDemo" do
platform :ios, "7.0"
platform :ios, "10.0"

# pod 'Qiniu', '~> 8.1.1'
pod 'Qiniu',:path => '../'
Expand Down
2 changes: 2 additions & 0 deletions QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.qiniu.QiniuDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_SWIFT_SYMBOLS = YES;
SUPPORTS_MACCATALYST = YES;
};
name = Debug;
Expand All @@ -569,6 +570,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.qiniu.QiniuDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
STRIP_SWIFT_SYMBOLS = YES;
SUPPORTS_MACCATALYST = YES;
};
name = Release;
Expand Down
32 changes: 16 additions & 16 deletions QiniuDemo/QiniuDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,27 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath {
// }
// option:uploadOption];

long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil] fileSize];
NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:filePath];
[upManager putInputStream:stream sourceId:filePath.lastPathComponent size:fileSize fileName:filePath.lastPathComponent key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
NSLog(@"info ===== %@", info);
NSLog(@"resp ===== %@", resp);

[weakSelf changeUploadState:UploadStatePrepare];
[weakSelf alertMessage:info.message];
} option:uploadOption];

// NSURL *url = [NSURL fileURLWithPath:filePath];
// PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
// PHAsset *asset = [self getPHAssert];
// [upManager putPHAsset:asset key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
// long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil] fileSize];
// NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:filePath];
// [upManager putInputStream:stream sourceId:filePath.lastPathComponent size:fileSize fileName:filePath.lastPathComponent key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
// NSLog(@"info ===== %@", info);
// NSLog(@"resp ===== %@", resp);
//
// [weakSelf changeUploadState:UploadStatePrepare];
// [weakSelf alertMessage:info.message];
// }
// option:uploadOption];
// } option:uploadOption];

NSURL *url = [NSURL fileURLWithPath:filePath];
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
PHAsset *asset = [self getPHAssert];
[upManager putPHAsset:asset key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
NSLog(@"info ===== %@", info);
NSLog(@"resp ===== %@", resp);

[weakSelf changeUploadState:UploadStatePrepare];
[weakSelf alertMessage:info.message];
}
option:uploadOption];
}

- (PHAsset *)getPHAssert {
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/Storage/QNUploadInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
/// @param dataSize 读取数据大小
/// @param dataOffset 数据偏移量
/// @param error 读取时的错误信息
- (NSData *)readData:(NSInteger)dataSize dataOffset:(long)dataOffset error:(NSError **)error;
- (NSData *)readData:(NSInteger)dataSize dataOffset:(long long)dataOffset error:(NSError **)error;

/// 关闭流
- (void)close;
Expand Down
6 changes: 3 additions & 3 deletions QiniuSDK/Storage/QNUploadInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@interface QNUploadInfo()

@property(nonatomic, copy)NSString *sourceId;
@property(nonatomic, assign)long sourceSize;
@property(nonatomic, assign)long long sourceSize;
@property(nonatomic, copy)NSString *fileName;

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

- (long)getSourceSize {
- (long long)getSourceSize {
return [self.source getSize];
}

Expand Down Expand Up @@ -91,7 +91,7 @@ - (void)clearUploadState {
- (void)checkInfoStateAndUpdate {
}

- (NSData *)readData:(NSInteger)dataSize dataOffset:(long)dataOffset error:(NSError **)error {
- (NSData *)readData:(NSInteger)dataSize dataOffset:(long long)dataOffset error:(NSError **)error {
if (!self.source) {
*error = [NSError errorWithDomain:NSStreamSOCKSErrorDomain code:kQNLocalIOError userInfo:@{NSLocalizedDescriptionKey : @"file is not exist"}];
return nil;
Expand Down
4 changes: 2 additions & 2 deletions QiniuSDK/Storage/QNUploadInfoV1.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ - (QNUploadBlock *)nextUploadBlock:(NSError **)error {
}

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

block = [[QNUploadBlock alloc] initWithOffset:blockOffset blockSize:kBlockSize dataSize:self.dataSize index:self.blockList.count];
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/Storage/QNUploadSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return 资源大小
*/
- (long)getSize;
- (long long)getSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YangSen-qn 接口返回类型变化 要考虑兼容性问题

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种是兼容的


/**
* 读取数据
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/Storage/QNUploadSourceFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (nonnull NSString *)getFileName {
return [[self.file path] lastPathComponent];
}

- (long)getSize {
- (long long)getSize {
return [self.file size];
}

Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/Storage/QNUploadSourceStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (NSString *)getFileName {
return self.fileName;
}

- (long)getSize {
- (long long)getSize {
if (self.size > kQNUnknownSourceSize) {
return self.size;
} else {
Expand Down
38 changes: 30 additions & 8 deletions QiniuSDK/Utils/QNPHAssetFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ - (NSData *)read:(long)offset
NSData *data = nil;
@try {
[_lock lock];
if (_assetData != nil) {
data = [_assetData subdataWithRange:NSMakeRange(offset, (unsigned int)size)];
} else {
if (_assetData != nil && offset < _assetData.length) {
NSInteger realSize = MIN(size, _assetData.length - offset);
data = [_assetData subdataWithRange:NSMakeRange(offset, realSize)];
} else if (_file != nil && offset < _fileSize) {
[_file seekToFileOffset:offset];
data = [_file readDataOfLength:size];
} else {
data = [NSData data];
}
} @catch (NSException *exception) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:kQNFileError userInfo:@{NSLocalizedDescriptionKey : exception.reason}];
Expand Down Expand Up @@ -157,11 +160,30 @@ - (void)getImageInfo {
options.networkAccessAllowed = NO;
options.synchronous = YES;

[[PHImageManager defaultManager] requestImageDataForAsset:self.phAsset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
self.assetData = imageData;
self.fileSize = imageData.length;
self.hasRealFilePath = NO;
}];
#if TARGET_OS_MACCATALYST
if (@available(macOS 10.15, *)) {
[[PHImageManager defaultManager] requestImageDataAndOrientationForAsset:self.phAsset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, CGImagePropertyOrientation orientation, NSDictionary *info) {
self.assetData = imageData;
self.fileSize = imageData.length;
self.hasRealFilePath = NO;
}];
}
#else
if (@available(iOS 13, *)) {
[[PHImageManager defaultManager] requestImageDataAndOrientationForAsset:self.phAsset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, CGImagePropertyOrientation orientation, NSDictionary *info) {
self.assetData = imageData;
self.fileSize = imageData.length;
self.hasRealFilePath = NO;
}];
} else {
[[PHImageManager defaultManager] requestImageDataForAsset:self.phAsset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
self.assetData = imageData;
self.fileSize = imageData.length;
self.hasRealFilePath = NO;
}];
}
#endif

}

- (void)getVideoInfo {
Expand Down
9 changes: 7 additions & 2 deletions QiniuSDK/Utils/QNPHAssetResource.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ - (NSData *)read:(long)offset
NSData *data = nil;
@try {
[_lock lock];
NSRange subRange = NSMakeRange(offset, size);
if (!self.assetData) {
self.assetData = [self fetchDataFromAsset:self.phAssetResource error:error];
}
data = [self.assetData subdataWithRange:subRange];

if (_assetData != nil && offset < _assetData.length) {
NSInteger realSize = MIN(size, _assetData.length - offset);
data = [_assetData subdataWithRange:NSMakeRange(offset, realSize)];
} else {
data = [NSData data];
}
} @catch (NSException *exception) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:kQNFileError userInfo:@{NSLocalizedDescriptionKey : exception.reason}];
NSLog(@"read file failed reason: %@ \n%@", exception.reason, exception.callStackSymbols);
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/Utils/QNVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
/**
* sdk 版本
*/
static NSString *const kQiniuVersion = @"8.3.1";
static NSString *const kQiniuVersion = @"8.3.2";
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
通过 CocoaPods

```ruby
pod "Qiniu", "~> 8.3.1"
pod "Qiniu", "~> 8.3.2"
```

## 运行环境
Expand Down