Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix iOS 18 PHAssetResource fetch fail #448

Merged
merged 3 commits into from
Nov 14, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#Changelog
## 8.8.1(2024-10-25)
- 处理 iOS 18 PHAssetResource 信息 fetch 失败而导致异常问题

## 8.8.0(2024-06-24)
- 上传支持加速域名
- 查询区域移除备用域名:api.qiniu.com
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.8.0'
s.version = '8.8.1'
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
1 change: 1 addition & 0 deletions QiniuDemo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target "QiniuDemo" do
# pod 'Qiniu', '7.1.7'
pod 'Qiniu',:path => '../'
pod 'HappyDNS',:path => '../../happy-dns-objc'
pod 'TZImagePickerController', '~> 3.8.7'
end

target "QiniuDemoTests" do
Expand Down
8 changes: 8 additions & 0 deletions QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
26F62ADDD5B6306E978C9A3F /* libPods-QiniuDemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */; };
45169DF22C3D263200737759 /* Uploader.m in Sources */ = {isa = PBXBuildFile; fileRef = 45169DF12C3D263200737759 /* Uploader.m */; };
4561F02C28D9A6F80098A697 /* UploadResource_14M.zip in Resources */ = {isa = PBXBuildFile; fileRef = 4561F02B28D9A6F80098A697 /* UploadResource_14M.zip */; };
45E6080929ADD57100634200 /* UploadResource_1G.zip in Resources */ = {isa = PBXBuildFile; fileRef = 45E6080829ADD57100634200 /* UploadResource_1G.zip */; };
93D230241C86D7F700434F6D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230231C86D7F700434F6D /* main.m */; };
Expand Down Expand Up @@ -42,6 +43,8 @@
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>"; };
3189882026469145003CCA68 /* QiniuDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = QiniuDemo.entitlements; sourceTree = "<group>"; };
45169DF02C3D263200737759 /* Uploader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Uploader.h; sourceTree = "<group>"; };
45169DF12C3D263200737759 /* Uploader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Uploader.m; sourceTree = "<group>"; };
4561F02B28D9A6F80098A697 /* UploadResource_14M.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = UploadResource_14M.zip; sourceTree = "<group>"; };
4561F02F28D9AB090098A697 /* Configure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Configure.h; sourceTree = "<group>"; };
45E6080829ADD57100634200 /* UploadResource_1G.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = UploadResource_1G.zip; sourceTree = "<group>"; };
Expand Down Expand Up @@ -169,6 +172,8 @@
93D230301C86D7F700434F6D /* LaunchScreen.storyboard */,
93D230331C86D7F700434F6D /* Info.plist */,
93D230221C86D7F700434F6D /* Supporting Files */,
45169DF02C3D263200737759 /* Uploader.h */,
45169DF12C3D263200737759 /* Uploader.m */,
);
path = QiniuDemo;
sourceTree = "<group>";
Expand Down Expand Up @@ -340,11 +345,13 @@
"${PODS_ROOT}/Target Support Files/Pods-QiniuDemo/Pods-QiniuDemo-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/HappyDNS/HappyDNS.privacy.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/Qiniu/Qiniu.privacy.bundle",
"${PODS_ROOT}/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/HappyDNS.privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Qiniu.privacy.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/TZImagePickerController.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -395,6 +402,7 @@
buildActionMask = 2147483647;
files = (
93D2302A1C86D7F700434F6D /* ViewController.m in Sources */,
45169DF22C3D263200737759 /* Uploader.m in Sources */,
93D230271C86D7F700434F6D /* AppDelegate.m in Sources */,
93D230241C86D7F700434F6D /* main.m in Sources */,
);
Expand Down
17 changes: 17 additions & 0 deletions QiniuDemo/QiniuDemo/Uploader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Uploader.h
// QiniuDemo
//
// Created by yangsen on 2024/7/9.
// Copyright © 2024 Aaron. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface Uploader : NSObject

@end

NS_ASSUME_NONNULL_END
135 changes: 135 additions & 0 deletions QiniuDemo/QiniuDemo/Uploader.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//
// Uploader.m
// QiniuDemo
//
// Created by yangsen on 2024/7/9.
// Copyright © 2024 Aaron. All rights reserved.
//

#import "Uploader.h"
#import <QiniuSDK.h>

@implementation Uploader

- (void)upload {

QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
// Upload_Domain1 和 Upload_Domain2 为加速域名,可以参考七牛云存储控制台域名管理页面,建议通过用户服务下发,不要硬编码
builder.zone = [[QNFixedZone alloc] initWithUpDomainList:@[@"Upload_Domain1", @"Upload_Domain2"]];
}];

QNUploadManager *manager = [[QNUploadManager alloc] initWithConfiguration:config];

// QNFixedZone *zone = [QNFixedZone createWithRegionId:@"z0"];

QNAutoZone *zone = [QNAutoZone zoneWithUcHosts:@[@"UCHost0", @"UCHost1"]];

}

- (void)upload0 {


QNConfiguration *configuration = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
// 配置上传区域,Host0、Host1 建议通过服务方式下发
builder.zone = [[QNFixedZone alloc] initWithUpDomainList:@[@"Host0", @"Host2"]];
// 分片上传阈值:4MB,大于 4MB 采用分片上传,小于 4MB 采用表单上传
builder.putThreshold = 4*1024*1024;
// 开启并发分片上传
builder.useConcurrentResumeUpload = true;
// 使用分片 V2
builder.resumeUploadVersion = QNResumeUploadVersionV2;
// 文件分片上传时断点续传信息保存,表单上传此配置无效
NSString *recorderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
builder.recorder = [QNFileRecorder fileRecorderWithFolder:recorderPath error:nil];
}];
QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:configuration];

__weak typeof(self) weakSelf = self;
QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:nil progressHandler:^(NSString *key, float percent) {
NSLog(@"percent == %.2f", percent);
}
params:nil
checkCrc:NO
cancellationSignal:^BOOL{
// 当需要取消时,此处返回 true,SDK 内部会多次检查返回值,当返回值为 true 时会取消上传操作
return false;
}];

NSString *filePath = @""; // 文件路径
NSString *key = @""; // 文件 key
NSString *uploadToken = @""; // 上传的 Token
[upManager putFile:filePath key:key token:uploadToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
if (info.isOK) {
// 上传成功
} else {
// 上传失败
}
} option:uploadOption];
}


- (void)upload1 {

QNConfiguration *configuration = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
builder.zone = [[QNAutoZone alloc] init]; // 配置上传区域,使用 QNAutoZone
builder.recorderKeyGen = ^NSString *(NSString *uploadKey, NSString *filePath) {
// 自定义 文件分片上传时断点续传信息保存的 key,默认使用 uploadKey
return [NSString stringWithFormat:@"%@-%@", uploadKey, filePath];
};
// 文件分片上传时断点续传信息保存,表单上传此配置无效
NSString *recorderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
builder.recorder = [QNFileRecorder fileRecorderWithFolder:recorderPath error:nil];

// 文件采用分片上传时,分片大小为 2MB
builder.chunkSize = 2*1024*1024;

// 分片上传阈值:4MB,大于 4MB 采用分片上传,小于 4MB 采用表单上传
builder.putThreshold = 4*1024*1024;

// 单个域名/IP请求失败后最大重试次数为 1 次
builder.retryMax = 1;

// 重试时间间隔:0.5s
builder.retryInterval = 0.5;

// 请求超时时间:60s
builder.timeoutInterval = 60;

// 使用 HTTPS
builder.useHttps = true;

// 使用备用域名进行重试
builder.allowBackupHost = true;

// 开启加速上传
builder.accelerateUploading = true;

// 开启并发分片上传
builder.useConcurrentResumeUpload = true;

// 使用并发分片上传时,一个文件并发上传的分片个数
builder.concurrentTaskCount = 2;

// 使用分片 V2
builder.resumeUploadVersion = QNResumeUploadVersionV2;
}];


// 指定文件 mime type
NSString *mimeType = @"";
// 用于服务器上传回调通知的自定义参数,参数的key必须以x: 开头 eg: x:foo
NSDictionary <NSString *, NSString *> * params = @{};
// 用于设置meta数据,参数的key必须以x-qn-meta- 开头 eg: x-qn-meta-key
NSDictionary <NSString *, NSString *> * metaDataParams = @{};
BOOL checkCrc = true;
QNUploadOption *option = [[QNUploadOption alloc] initWithMime:mimeType
byteProgressHandler:^(NSString *key, long long uploadBytes, long long totalBytes) {
// 处理上传进度
} params:params metaDataParams:metaDataParams checkCrc:checkCrc cancellationSignal:^BOOL{
// 当需要取消时,此处返回 false,SDK 内部会不间断检测此返回值
return false;
}];


}
@end
Loading
Loading