Skip to content

Commit 1df2273

Browse files
authored
fix iOS 18 PHAssetResource fetch fail (#448)
1 parent 69a65f7 commit 1df2273

File tree

11 files changed

+313
-147
lines changed

11 files changed

+313
-147
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#Changelog
2+
## 8.8.1(2024-10-25)
3+
- 处理 iOS 18 PHAssetResource 信息 fetch 失败而导致异常问题
4+
25
## 8.8.0(2024-06-24)
36
- 上传支持加速域名
47
- 查询区域移除备用域名:api.qiniu.com

Qiniu.podspec

+1-1
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.8.0'
3+
s.version = '8.8.1'
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

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ target "QiniuDemo" do
77
# pod 'Qiniu', '7.1.7'
88
pod 'Qiniu',:path => '../'
99
pod 'HappyDNS',:path => '../../happy-dns-objc'
10+
pod 'TZImagePickerController', '~> 3.8.7'
1011
end
1112

1213
target "QiniuDemoTests" do

QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
26F62ADDD5B6306E978C9A3F /* libPods-QiniuDemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */; };
11+
45169DF22C3D263200737759 /* Uploader.m in Sources */ = {isa = PBXBuildFile; fileRef = 45169DF12C3D263200737759 /* Uploader.m */; };
1112
4561F02C28D9A6F80098A697 /* UploadResource_14M.zip in Resources */ = {isa = PBXBuildFile; fileRef = 4561F02B28D9A6F80098A697 /* UploadResource_14M.zip */; };
1213
45E6080929ADD57100634200 /* UploadResource_1G.zip in Resources */ = {isa = PBXBuildFile; fileRef = 45E6080829ADD57100634200 /* UploadResource_1G.zip */; };
1314
93D230241C86D7F700434F6D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D230231C86D7F700434F6D /* main.m */; };
@@ -42,6 +43,8 @@
4243
14CB2139715DD7B6FD5B146E /* libPods-QiniuDemoTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuDemoTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4344
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>"; };
4445
3189882026469145003CCA68 /* QiniuDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = QiniuDemo.entitlements; sourceTree = "<group>"; };
46+
45169DF02C3D263200737759 /* Uploader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Uploader.h; sourceTree = "<group>"; };
47+
45169DF12C3D263200737759 /* Uploader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Uploader.m; sourceTree = "<group>"; };
4548
4561F02B28D9A6F80098A697 /* UploadResource_14M.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = UploadResource_14M.zip; sourceTree = "<group>"; };
4649
4561F02F28D9AB090098A697 /* Configure.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Configure.h; sourceTree = "<group>"; };
4750
45E6080829ADD57100634200 /* UploadResource_1G.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = UploadResource_1G.zip; sourceTree = "<group>"; };
@@ -169,6 +172,8 @@
169172
93D230301C86D7F700434F6D /* LaunchScreen.storyboard */,
170173
93D230331C86D7F700434F6D /* Info.plist */,
171174
93D230221C86D7F700434F6D /* Supporting Files */,
175+
45169DF02C3D263200737759 /* Uploader.h */,
176+
45169DF12C3D263200737759 /* Uploader.m */,
172177
);
173178
path = QiniuDemo;
174179
sourceTree = "<group>";
@@ -340,11 +345,13 @@
340345
"${PODS_ROOT}/Target Support Files/Pods-QiniuDemo/Pods-QiniuDemo-resources.sh",
341346
"${PODS_CONFIGURATION_BUILD_DIR}/HappyDNS/HappyDNS.privacy.bundle",
342347
"${PODS_CONFIGURATION_BUILD_DIR}/Qiniu/Qiniu.privacy.bundle",
348+
"${PODS_ROOT}/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZImagePickerController.bundle",
343349
);
344350
name = "[CP] Copy Pods Resources";
345351
outputPaths = (
346352
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/HappyDNS.privacy.bundle",
347353
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Qiniu.privacy.bundle",
354+
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/TZImagePickerController.bundle",
348355
);
349356
runOnlyForDeploymentPostprocessing = 0;
350357
shellPath = /bin/sh;
@@ -395,6 +402,7 @@
395402
buildActionMask = 2147483647;
396403
files = (
397404
93D2302A1C86D7F700434F6D /* ViewController.m in Sources */,
405+
45169DF22C3D263200737759 /* Uploader.m in Sources */,
398406
93D230271C86D7F700434F6D /* AppDelegate.m in Sources */,
399407
93D230241C86D7F700434F6D /* main.m in Sources */,
400408
);

QiniuDemo/QiniuDemo/Uploader.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Uploader.h
3+
// QiniuDemo
4+
//
5+
// Created by yangsen on 2024/7/9.
6+
// Copyright © 2024 Aaron. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface Uploader : NSObject
14+
15+
@end
16+
17+
NS_ASSUME_NONNULL_END

QiniuDemo/QiniuDemo/Uploader.m

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
//
2+
// Uploader.m
3+
// QiniuDemo
4+
//
5+
// Created by yangsen on 2024/7/9.
6+
// Copyright © 2024 Aaron. All rights reserved.
7+
//
8+
9+
#import "Uploader.h"
10+
#import <QiniuSDK.h>
11+
12+
@implementation Uploader
13+
14+
- (void)upload {
15+
16+
QNConfiguration *config = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
17+
// Upload_Domain1 和 Upload_Domain2 为加速域名,可以参考七牛云存储控制台域名管理页面,建议通过用户服务下发,不要硬编码
18+
builder.zone = [[QNFixedZone alloc] initWithUpDomainList:@[@"Upload_Domain1", @"Upload_Domain2"]];
19+
}];
20+
21+
QNUploadManager *manager = [[QNUploadManager alloc] initWithConfiguration:config];
22+
23+
// QNFixedZone *zone = [QNFixedZone createWithRegionId:@"z0"];
24+
25+
QNAutoZone *zone = [QNAutoZone zoneWithUcHosts:@[@"UCHost0", @"UCHost1"]];
26+
27+
}
28+
29+
- (void)upload0 {
30+
31+
32+
QNConfiguration *configuration = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
33+
// 配置上传区域,Host0、Host1 建议通过服务方式下发
34+
builder.zone = [[QNFixedZone alloc] initWithUpDomainList:@[@"Host0", @"Host2"]];
35+
// 分片上传阈值:4MB,大于 4MB 采用分片上传,小于 4MB 采用表单上传
36+
builder.putThreshold = 4*1024*1024;
37+
// 开启并发分片上传
38+
builder.useConcurrentResumeUpload = true;
39+
// 使用分片 V2
40+
builder.resumeUploadVersion = QNResumeUploadVersionV2;
41+
// 文件分片上传时断点续传信息保存,表单上传此配置无效
42+
NSString *recorderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
43+
builder.recorder = [QNFileRecorder fileRecorderWithFolder:recorderPath error:nil];
44+
}];
45+
QNUploadManager *upManager = [[QNUploadManager alloc] initWithConfiguration:configuration];
46+
47+
__weak typeof(self) weakSelf = self;
48+
QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:nil progressHandler:^(NSString *key, float percent) {
49+
NSLog(@"percent == %.2f", percent);
50+
}
51+
params:nil
52+
checkCrc:NO
53+
cancellationSignal:^BOOL{
54+
// 当需要取消时,此处返回 true,SDK 内部会多次检查返回值,当返回值为 true 时会取消上传操作
55+
return false;
56+
}];
57+
58+
NSString *filePath = @""; // 文件路径
59+
NSString *key = @""; // 文件 key
60+
NSString *uploadToken = @""; // 上传的 Token
61+
[upManager putFile:filePath key:key token:uploadToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
62+
if (info.isOK) {
63+
// 上传成功
64+
} else {
65+
// 上传失败
66+
}
67+
} option:uploadOption];
68+
}
69+
70+
71+
- (void)upload1 {
72+
73+
QNConfiguration *configuration = [QNConfiguration build:^(QNConfigurationBuilder *builder) {
74+
builder.zone = [[QNAutoZone alloc] init]; // 配置上传区域,使用 QNAutoZone
75+
builder.recorderKeyGen = ^NSString *(NSString *uploadKey, NSString *filePath) {
76+
// 自定义 文件分片上传时断点续传信息保存的 key,默认使用 uploadKey
77+
return [NSString stringWithFormat:@"%@-%@", uploadKey, filePath];
78+
};
79+
// 文件分片上传时断点续传信息保存,表单上传此配置无效
80+
NSString *recorderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
81+
builder.recorder = [QNFileRecorder fileRecorderWithFolder:recorderPath error:nil];
82+
83+
// 文件采用分片上传时,分片大小为 2MB
84+
builder.chunkSize = 2*1024*1024;
85+
86+
// 分片上传阈值:4MB,大于 4MB 采用分片上传,小于 4MB 采用表单上传
87+
builder.putThreshold = 4*1024*1024;
88+
89+
// 单个域名/IP请求失败后最大重试次数为 1 次
90+
builder.retryMax = 1;
91+
92+
// 重试时间间隔:0.5s
93+
builder.retryInterval = 0.5;
94+
95+
// 请求超时时间:60s
96+
builder.timeoutInterval = 60;
97+
98+
// 使用 HTTPS
99+
builder.useHttps = true;
100+
101+
// 使用备用域名进行重试
102+
builder.allowBackupHost = true;
103+
104+
// 开启加速上传
105+
builder.accelerateUploading = true;
106+
107+
// 开启并发分片上传
108+
builder.useConcurrentResumeUpload = true;
109+
110+
// 使用并发分片上传时,一个文件并发上传的分片个数
111+
builder.concurrentTaskCount = 2;
112+
113+
// 使用分片 V2
114+
builder.resumeUploadVersion = QNResumeUploadVersionV2;
115+
}];
116+
117+
118+
// 指定文件 mime type
119+
NSString *mimeType = @"";
120+
// 用于服务器上传回调通知的自定义参数,参数的key必须以x: 开头 eg: x:foo
121+
NSDictionary <NSString *, NSString *> * params = @{};
122+
// 用于设置meta数据,参数的key必须以x-qn-meta- 开头 eg: x-qn-meta-key
123+
NSDictionary <NSString *, NSString *> * metaDataParams = @{};
124+
BOOL checkCrc = true;
125+
QNUploadOption *option = [[QNUploadOption alloc] initWithMime:mimeType
126+
byteProgressHandler:^(NSString *key, long long uploadBytes, long long totalBytes) {
127+
// 处理上传进度
128+
} params:params metaDataParams:metaDataParams checkCrc:checkCrc cancellationSignal:^BOOL{
129+
// 当需要取消时,此处返回 false,SDK 内部会不间断检测此返回值
130+
return false;
131+
}];
132+
133+
134+
}
135+
@end

0 commit comments

Comments
 (0)