From 3db00f9af1e990e30ef68c90d0f6214695de04f9 Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 20 Oct 2023 03:47:55 -0500 Subject: [PATCH] add createWithRegionId (#437) --- QiniuSDK.xcodeproj/project.pbxproj | 25 ++++++++------------- QiniuSDK/Common/QNFixedZone.h | 25 +++++++++++++++------ QiniuSDK/Common/QNFixedZone.m | 8 +++++++ QiniuSDK/Utils/QNDefine.h | 3 +++ QiniuSDKTests/QNFixZoneTest.m | 36 ++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 QiniuSDKTests/QNFixZoneTest.m diff --git a/QiniuSDK.xcodeproj/project.pbxproj b/QiniuSDK.xcodeproj/project.pbxproj index 781818cd..4529c744 100644 --- a/QiniuSDK.xcodeproj/project.pbxproj +++ b/QiniuSDK.xcodeproj/project.pbxproj @@ -21,8 +21,6 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ - 0CD9B2165D33CBCFF01AAE0B /* libPods-QiniuSDK_MacTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */; }; - 12E9CD5CF6B4132A6ED0D7D4 /* libPods-QiniuSDK_Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */; }; 3115471D243476CF00D77B8B /* QNTransactionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3115471C243476CF00D77B8B /* QNTransactionTest.m */; }; 3115471E243476D600D77B8B /* QNTransactionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3115471C243476CF00D77B8B /* QNTransactionTest.m */; }; 311ADD1F2577482C00A6E15E /* QNUploadBaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 311ADD1A2577482200A6E15E /* QNUploadBaseTest.m */; }; @@ -358,6 +356,8 @@ 4551E56724D0065100447285 /* NSData+QNMD5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4551E56524D0065100447285 /* NSData+QNMD5.h */; }; 4551E56824D0065100447285 /* NSData+QNMD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4551E56624D0065100447285 /* NSData+QNMD5.m */; }; 4551E56924D0065100447285 /* NSData+QNMD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4551E56624D0065100447285 /* NSData+QNMD5.m */; }; + 45CBC6C32AA9B05A00962B47 /* QNFixZoneTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */; }; + 45CBC6C42AA9B05A00962B47 /* QNFixZoneTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */; }; 45CBC6D22ABA9FFF00962B47 /* QNCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 45CBC6D02ABA9FFF00962B47 /* QNCache.h */; }; 45CBC6D32ABA9FFF00962B47 /* QNCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 45CBC6D02ABA9FFF00962B47 /* QNCache.h */; }; 45CBC6D42ABA9FFF00962B47 /* QNCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6D12ABA9FFF00962B47 /* QNCache.m */; }; @@ -366,8 +366,6 @@ 45CBC6D82ABAE24900962B47 /* QNCacheTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6D62ABAE24900962B47 /* QNCacheTest.m */; }; 45E0B28A2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */; }; 45E0B28B2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */; }; - 8D0FB78D364BAEE65E20A604 /* libPods-QiniuSDK_iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */; }; - C275A64FFBE81B9CE7DDC79E /* libPods-QiniuSDK_iOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */; }; CC25135C244C7EB3003F4C65 /* QNBaseUpload.h in Headers */ = {isa = PBXBuildFile; fileRef = CC25135A244C7EB3003F4C65 /* QNBaseUpload.h */; }; CC25135D244C7EB3003F4C65 /* QNBaseUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = CC25135B244C7EB3003F4C65 /* QNBaseUpload.m */; }; CC25135E244C7EB3003F4C65 /* QNBaseUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = CC25135B244C7EB3003F4C65 /* QNBaseUpload.m */; }; @@ -437,7 +435,6 @@ /* Begin PBXFileReference section */ 135958056D8FF4295F3D9AB0 /* Pods-QiniuSDK_iOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_iOSTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_iOSTests/Pods-QiniuSDK_iOSTests.release.xcconfig"; sourceTree = ""; }; - 24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_MacTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 3115471C243476CF00D77B8B /* QNTransactionTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNTransactionTest.m; sourceTree = ""; }; 311ADD192577482200A6E15E /* QNUploadBaseTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUploadBaseTest.h; sourceTree = ""; }; 311ADD1A2577482200A6E15E /* QNUploadBaseTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUploadBaseTest.m; sourceTree = ""; }; @@ -602,12 +599,12 @@ 4551E55E24CE81DA00447285 /* QNInetAddress.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNInetAddress.m; sourceTree = ""; }; 4551E56524D0065100447285 /* NSData+QNMD5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+QNMD5.h"; sourceTree = ""; }; 4551E56624D0065100447285 /* NSData+QNMD5.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+QNMD5.m"; sourceTree = ""; }; + 45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNFixZoneTest.m; sourceTree = ""; }; 45CBC6D02ABA9FFF00962B47 /* QNCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNCache.h; sourceTree = ""; }; 45CBC6D12ABA9FFF00962B47 /* QNCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNCache.m; sourceTree = ""; }; 45CBC6D62ABAE24900962B47 /* QNCacheTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNCacheTest.m; sourceTree = ""; }; 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNConfigurationTest.m; sourceTree = ""; }; 466E7AACB5F77BA0D4DE4070 /* Pods-QiniuSDK_MacTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_MacTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_MacTests/Pods-QiniuSDK_MacTests.debug.xcconfig"; sourceTree = ""; }; - 5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_iOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 6663602DA8CC701EA3B11F04 /* Pods-QiniuSDK_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_iOS/Pods-QiniuSDK_iOS.debug.xcconfig"; sourceTree = ""; }; 69B20FB4731F84969BC5AEBE /* Pods-QiniuSDK_Mac.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_Mac.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_Mac/Pods-QiniuSDK_Mac.debug.xcconfig"; sourceTree = ""; }; 6DD894AA2A19370381AD4201 /* Pods-QiniuSDK_iOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_iOSTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_iOSTests/Pods-QiniuSDK_iOSTests.debug.xcconfig"; sourceTree = ""; }; @@ -660,8 +657,6 @@ DFF525301A6235D100D02BA1 /* QNSessionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNSessionManager.m; sourceTree = ""; }; DFF525381A64079B00D02BA1 /* QNSessionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNSessionTest.m; sourceTree = ""; }; DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNFileRecorderTest.m; sourceTree = ""; }; - E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_Mac.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; FDEA88651DAC10D000D037E5 /* QNAutoZoneTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNAutoZoneTest.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -670,7 +665,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8D0FB78D364BAEE65E20A604 /* libPods-QiniuSDK_iOS.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -679,7 +673,6 @@ buildActionMask = 2147483647; files = ( DF293C9119DB85CB00799011 /* libz.dylib in Frameworks */, - 12E9CD5CF6B4132A6ED0D7D4 /* libPods-QiniuSDK_Mac.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -689,7 +682,6 @@ files = ( DF0A03231B3BABEC00E3778C /* QiniuSDK_Mac.dylib in Frameworks */, DF293C9219DB85EB00799011 /* libz.dylib in Frameworks */, - 0CD9B2165D33CBCFF01AAE0B /* libPods-QiniuSDK_MacTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -698,7 +690,6 @@ buildActionMask = 2147483647; files = ( DF0A03251B3BAC5700E3778C /* libQiniuSDK_iOS.a in Frameworks */, - C275A64FFBE81B9CE7DDC79E /* libPods-QiniuSDK_iOSTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -916,10 +907,6 @@ A955AABD20BF51BFE5032419 /* Frameworks */ = { isa = PBXGroup; children = ( - E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */, - 24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */, - F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */, - 5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */, ); name = Frameworks; sourceTree = ""; @@ -1074,6 +1061,7 @@ 316A4B822431C8BA007BF564 /* QNDnsPrefetcherTest.m */, DFA9B63E19DFD8C900A15FD1 /* QNEtagTest.m */, DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */, + 45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */, DF3C504619DD7BA6000F548F /* QNFormUploadTest.m */, 31259E3524E3D32700CF7531 /* QNGZipTest.m */, 31C30FAB2852EA7900BFD8F7 /* QNNetworkStatusTest.m */, @@ -1649,6 +1637,7 @@ 311ADD23257748A700A6E15E /* QNUploadFlowTest.m in Sources */, DF437CDF1B243A2C0099587B /* QNUpTokenTest.m in Sources */, 31DD31D624971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */, + 45CBC6C32AA9B05A00962B47 /* QNFixZoneTest.m in Sources */, 31A74BCA26E8A89C001EC948 /* QNUplogTest.m in Sources */, 31A1840E246942E0001D6EEE /* QNComplexUploadSceneTest.m in Sources */, DF3C504A19DD7D9F000F548F /* QNResumeUploadTest.m in Sources */, @@ -1776,6 +1765,7 @@ 311ADD24257748A700A6E15E /* QNUploadFlowTest.m in Sources */, DF0A03281B3BAC6E00E3778C /* QNFormUploadTest.m in Sources */, 31DD31D724971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */, + 45CBC6C42AA9B05A00962B47 /* QNFixZoneTest.m in Sources */, 31A74BCB26E8A89C001EC948 /* QNUplogTest.m in Sources */, 31A1840F246942E0001D6EEE /* QNComplexUploadSceneTest.m in Sources */, DF0A03291B3BAC6E00E3778C /* QNResumeUploadTest.m in Sources */, @@ -1948,6 +1938,7 @@ GENERATE_PKGINFO_FILE = YES; INFOPLIST_FILE = ""; MACOSX_DEPLOYMENT_TARGET = 10.14; + ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = QiniuSDK_Mac; }; name = Release; @@ -1984,6 +1975,7 @@ DEVELOPMENT_TEAM = ""; GENERATE_INFOPLIST_FILE = YES; GENERATE_PKGINFO_FILE = YES; + ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = QiniuSDK_MacTests; PROVISIONING_PROFILE_SPECIFIER = ""; }; @@ -2009,6 +2001,7 @@ COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GENERATE_PKGINFO_FILE = YES; + ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = QiniuSDK_iOS; SDKROOT = iphoneos; }; diff --git a/QiniuSDK/Common/QNFixedZone.h b/QiniuSDK/Common/QNFixedZone.h index a6c88d63..f1c74a2b 100644 --- a/QiniuSDK/Common/QNFixedZone.h +++ b/QiniuSDK/Common/QNFixedZone.h @@ -7,6 +7,7 @@ // #import "QNZone.h" +#import "QNDefine.h" NS_ASSUME_NONNULL_BEGIN @@ -17,42 +18,42 @@ NS_ASSUME_NONNULL_BEGIN * * @return 实例 */ -+ (instancetype)zone0; ++ (instancetype)zone0 kQNDeprecated("use createWithRegionId instead"); /** * zoneCnEast2 华东-浙江2 * * @return 实例 */ -+ (instancetype)zoneCnEast2; ++ (instancetype)zoneCnEast2 kQNDeprecated("use createWithRegionId instead"); /** * zone 1 华北 * * @return 实例 */ -+ (instancetype)zone1; ++ (instancetype)zone1 kQNDeprecated("use createWithRegionId instead"); /** * zone 2 华南 * * @return 实例 */ -+ (instancetype)zone2; ++ (instancetype)zone2 kQNDeprecated("use createWithRegionId instead"); /** * zone Na0 北美 * * @return 实例 */ -+ (instancetype)zoneNa0; ++ (instancetype)zoneNa0 kQNDeprecated("use createWithRegionId instead"); /** * zone As0 新加坡 * * @return 实例 */ -+ (instancetype)zoneAs0; ++ (instancetype)zoneAs0 kQNDeprecated("use createWithRegionId instead"); /** * Zone初始化方法 @@ -71,10 +72,20 @@ NS_ASSUME_NONNULL_BEGIN */ + (instancetype)createWithHost:(NSArray *)upList; +/** + * Zone初始化方法 + * regionId 参考链接:https://developer.qiniu.com/kodo/1671/region-endpoint-fq + * + * @param regionId 根据区域 ID 创建 Zone + * + * @return Zone 实例 + */ ++ (instancetype)createWithRegionId:(NSString *)regionId; + /** * 获取本地所有固定zone信息 */ -+ (QNFixedZone *)localsZoneInfo; ++ (QNFixedZone *)localsZoneInfo DEPRECATED_ATTRIBUTE; /** * 合并区域 diff --git a/QiniuSDK/Common/QNFixedZone.m b/QiniuSDK/Common/QNFixedZone.m index 2e5754eb..81485e91 100644 --- a/QiniuSDK/Common/QNFixedZone.m +++ b/QiniuSDK/Common/QNFixedZone.m @@ -120,6 +120,14 @@ + (instancetype)createWithHost:(NSArray *)upList { return [[QNFixedZone alloc] initWithUpDomainList:upList oldUpList:nil regionId:nil]; } ++ (instancetype)createWithRegionId:(NSString *)regionId { + NSArray *upList = @[ + [NSString stringWithFormat:@"upload-%@.qiniup.com", regionId], + [NSString stringWithFormat:@"up-%@.qiniup.com", regionId], + ]; + return [[QNFixedZone alloc] initWithUpDomainList:upList oldUpList:nil regionId:regionId]; +} + - (QNZonesInfo *)createZonesInfo:(NSArray *)upDomains regionId:(NSString *)regionId { return [self createZonesInfo:upDomains oldUpDomains:nil regionId:regionId]; diff --git a/QiniuSDK/Utils/QNDefine.h b/QiniuSDK/Utils/QNDefine.h index 18fc2a53..952b6bf3 100644 --- a/QiniuSDK/Utils/QNDefine.h +++ b/QiniuSDK/Utils/QNDefine.h @@ -13,3 +13,6 @@ #define kQNWeakObj(object) __weak typeof(object) weak_##object = object #define kQNStrongObj(object) __strong typeof(object) object = weak_##object + +// 过期 +#define kQNDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead) diff --git a/QiniuSDKTests/QNFixZoneTest.m b/QiniuSDKTests/QNFixZoneTest.m new file mode 100644 index 00000000..a2f60381 --- /dev/null +++ b/QiniuSDKTests/QNFixZoneTest.m @@ -0,0 +1,36 @@ +// +// QNFixZoneTest.m +// QiniuSDK +// +// Created by yangsen on 2023/9/7. +// Copyright © 2023 Qiniu. All rights reserved. +// + +#import +#import "QNFixedZone.h" +#import "QNZoneInfo.h" + +@interface QNFixZoneTest : XCTestCase + +@end + +@implementation QNFixZoneTest + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +- (void)testCreateByRegionId { + QNFixedZone *zone = [QNFixedZone createWithRegionId:@"na0"]; + QNZoneInfo *zoneInfo = [zone getZonesInfoWithToken:nil].zonesInfo[0]; + + XCTAssert([zoneInfo.regionId isEqualToString:@"na0"], @"regionId:%@", zoneInfo.regionId); + XCTAssert([zoneInfo.domains[0] isEqualToString:@"upload-na0.qiniup.com"], @"domains:%@", zoneInfo.domains); + XCTAssert([zoneInfo.domains[1] isEqualToString:@"up-na0.qiniup.com"], @"domains:%@", zoneInfo.domains); +} + +@end