diff --git a/CHANGELOG.md b/CHANGELOG.md index 68f1f58c..2cb6a0d5 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ #Changelog +## 8.3.2(2021-09-3) +## 优化 +- 处理 PHAssert 偶现上传失败问题 + ## 8.3.1(2021-08-12) ## 优化 - 对 DNS 域名预解析缓存增加缓存有效期,默认 10 分钟,支持手动修改有效期时长,kQNGlobalConfiguration.dnsCacheMaxTTL 单位为 s diff --git a/Qiniu.podspec b/Qiniu.podspec index 8ee2eb30..3bfe9f06 100755 --- a/Qiniu.podspec +++ b/Qiniu.podspec @@ -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' diff --git a/QiniuDemo/Podfile b/QiniuDemo/Podfile index 53815744..607b394c 100755 --- a/QiniuDemo/Podfile +++ b/QiniuDemo/Podfile @@ -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 => '../' diff --git a/QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj b/QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj index 744af5ad..b278c2f2 100644 --- a/QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj +++ b/QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj @@ -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; @@ -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; diff --git a/QiniuDemo/QiniuDemo/ViewController.m b/QiniuDemo/QiniuDemo/ViewController.m index 5c627161..fe42edc2 100755 --- a/QiniuDemo/QiniuDemo/ViewController.m +++ b/QiniuDemo/QiniuDemo/ViewController.m @@ -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 { diff --git a/QiniuSDK/Storage/QNUploadInfo.h b/QiniuSDK/Storage/QNUploadInfo.h index 92943269..54701087 100644 --- a/QiniuSDK/Storage/QNUploadInfo.h +++ b/QiniuSDK/Storage/QNUploadInfo.h @@ -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; diff --git a/QiniuSDK/Storage/QNUploadInfo.m b/QiniuSDK/Storage/QNUploadInfo.m index 2666e718..41bad48d 100644 --- a/QiniuSDK/Storage/QNUploadInfo.m +++ b/QiniuSDK/Storage/QNUploadInfo.m @@ -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 source; @@ -58,7 +58,7 @@ - (NSString *)getSourceId { return [self.source getId]; } -- (long)getSourceSize { +- (long long)getSourceSize { return [self.source getSize]; } @@ -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; diff --git a/QiniuSDK/Storage/QNUploadInfoV1.m b/QiniuSDK/Storage/QNUploadInfoV1.m index f66bb5fc..0c1ff112 100644 --- a/QiniuSDK/Storage/QNUploadInfoV1.m +++ b/QiniuSDK/Storage/QNUploadInfoV1.m @@ -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]; diff --git a/QiniuSDK/Storage/QNUploadSource.h b/QiniuSDK/Storage/QNUploadSource.h index f105595c..db6c20f6 100644 --- a/QiniuSDK/Storage/QNUploadSource.h +++ b/QiniuSDK/Storage/QNUploadSource.h @@ -51,7 +51,7 @@ NS_ASSUME_NONNULL_BEGIN * * @return 资源大小 */ -- (long)getSize; +- (long long)getSize; /** * 读取数据 diff --git a/QiniuSDK/Storage/QNUploadSourceFile.m b/QiniuSDK/Storage/QNUploadSourceFile.m index 69260625..a61104b7 100644 --- a/QiniuSDK/Storage/QNUploadSourceFile.m +++ b/QiniuSDK/Storage/QNUploadSourceFile.m @@ -38,7 +38,7 @@ - (nonnull NSString *)getFileName { return [[self.file path] lastPathComponent]; } -- (long)getSize { +- (long long)getSize { return [self.file size]; } diff --git a/QiniuSDK/Storage/QNUploadSourceStream.m b/QiniuSDK/Storage/QNUploadSourceStream.m index 7f1d9996..e824d059 100644 --- a/QiniuSDK/Storage/QNUploadSourceStream.m +++ b/QiniuSDK/Storage/QNUploadSourceStream.m @@ -49,7 +49,7 @@ - (NSString *)getFileName { return self.fileName; } -- (long)getSize { +- (long long)getSize { if (self.size > kQNUnknownSourceSize) { return self.size; } else { diff --git a/QiniuSDK/Utils/QNPHAssetFile.m b/QiniuSDK/Utils/QNPHAssetFile.m index e7754186..b9952eda 100644 --- a/QiniuSDK/Utils/QNPHAssetFile.m +++ b/QiniuSDK/Utils/QNPHAssetFile.m @@ -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}]; @@ -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 { diff --git a/QiniuSDK/Utils/QNPHAssetResource.m b/QiniuSDK/Utils/QNPHAssetResource.m index e481d83e..5c16275b 100755 --- a/QiniuSDK/Utils/QNPHAssetResource.m +++ b/QiniuSDK/Utils/QNPHAssetResource.m @@ -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); diff --git a/QiniuSDK/Utils/QNVersion.h b/QiniuSDK/Utils/QNVersion.h index abc3f71a..fb46604c 100755 --- a/QiniuSDK/Utils/QNVersion.h +++ b/QiniuSDK/Utils/QNVersion.h @@ -11,4 +11,4 @@ /** * sdk 版本 */ -static NSString *const kQiniuVersion = @"8.3.1"; +static NSString *const kQiniuVersion = @"8.3.2"; diff --git a/README.md b/README.md index 58708e40..fecf2dad 100755 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 通过 CocoaPods ```ruby -pod "Qiniu", "~> 8.3.1" +pod "Qiniu", "~> 8.3.2" ``` ## 运行环境