Skip to content

Commit 3db00f9

Browse files
authored
add createWithRegionId (#437)
1 parent 65caed5 commit 3db00f9

File tree

5 files changed

+74
-23
lines changed

5 files changed

+74
-23
lines changed

QiniuSDK.xcodeproj/project.pbxproj

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
/* End PBXAggregateTarget section */
2222

2323
/* Begin PBXBuildFile section */
24-
0CD9B2165D33CBCFF01AAE0B /* libPods-QiniuSDK_MacTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */; };
25-
12E9CD5CF6B4132A6ED0D7D4 /* libPods-QiniuSDK_Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */; };
2624
3115471D243476CF00D77B8B /* QNTransactionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3115471C243476CF00D77B8B /* QNTransactionTest.m */; };
2725
3115471E243476D600D77B8B /* QNTransactionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3115471C243476CF00D77B8B /* QNTransactionTest.m */; };
2826
311ADD1F2577482C00A6E15E /* QNUploadBaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 311ADD1A2577482200A6E15E /* QNUploadBaseTest.m */; };
@@ -358,6 +356,8 @@
358356
4551E56724D0065100447285 /* NSData+QNMD5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4551E56524D0065100447285 /* NSData+QNMD5.h */; };
359357
4551E56824D0065100447285 /* NSData+QNMD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4551E56624D0065100447285 /* NSData+QNMD5.m */; };
360358
4551E56924D0065100447285 /* NSData+QNMD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4551E56624D0065100447285 /* NSData+QNMD5.m */; };
359+
45CBC6C32AA9B05A00962B47 /* QNFixZoneTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */; };
360+
45CBC6C42AA9B05A00962B47 /* QNFixZoneTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */; };
361361
45CBC6D22ABA9FFF00962B47 /* QNCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 45CBC6D02ABA9FFF00962B47 /* QNCache.h */; };
362362
45CBC6D32ABA9FFF00962B47 /* QNCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 45CBC6D02ABA9FFF00962B47 /* QNCache.h */; };
363363
45CBC6D42ABA9FFF00962B47 /* QNCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6D12ABA9FFF00962B47 /* QNCache.m */; };
@@ -366,8 +366,6 @@
366366
45CBC6D82ABAE24900962B47 /* QNCacheTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6D62ABAE24900962B47 /* QNCacheTest.m */; };
367367
45E0B28A2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */; };
368368
45E0B28B2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */; };
369-
8D0FB78D364BAEE65E20A604 /* libPods-QiniuSDK_iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */; };
370-
C275A64FFBE81B9CE7DDC79E /* libPods-QiniuSDK_iOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */; };
371369
CC25135C244C7EB3003F4C65 /* QNBaseUpload.h in Headers */ = {isa = PBXBuildFile; fileRef = CC25135A244C7EB3003F4C65 /* QNBaseUpload.h */; };
372370
CC25135D244C7EB3003F4C65 /* QNBaseUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = CC25135B244C7EB3003F4C65 /* QNBaseUpload.m */; };
373371
CC25135E244C7EB3003F4C65 /* QNBaseUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = CC25135B244C7EB3003F4C65 /* QNBaseUpload.m */; };
@@ -437,7 +435,6 @@
437435

438436
/* Begin PBXFileReference section */
439437
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 = "<group>"; };
440-
24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_MacTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
441438
3115471C243476CF00D77B8B /* QNTransactionTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNTransactionTest.m; sourceTree = "<group>"; };
442439
311ADD192577482200A6E15E /* QNUploadBaseTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUploadBaseTest.h; sourceTree = "<group>"; };
443440
311ADD1A2577482200A6E15E /* QNUploadBaseTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUploadBaseTest.m; sourceTree = "<group>"; };
@@ -602,12 +599,12 @@
602599
4551E55E24CE81DA00447285 /* QNInetAddress.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNInetAddress.m; sourceTree = "<group>"; };
603600
4551E56524D0065100447285 /* NSData+QNMD5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+QNMD5.h"; sourceTree = "<group>"; };
604601
4551E56624D0065100447285 /* NSData+QNMD5.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+QNMD5.m"; sourceTree = "<group>"; };
602+
45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNFixZoneTest.m; sourceTree = "<group>"; };
605603
45CBC6D02ABA9FFF00962B47 /* QNCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNCache.h; sourceTree = "<group>"; };
606604
45CBC6D12ABA9FFF00962B47 /* QNCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNCache.m; sourceTree = "<group>"; };
607605
45CBC6D62ABAE24900962B47 /* QNCacheTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNCacheTest.m; sourceTree = "<group>"; };
608606
45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNConfigurationTest.m; sourceTree = "<group>"; };
609607
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 = "<group>"; };
610-
5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_iOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
611608
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 = "<group>"; };
612609
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 = "<group>"; };
613610
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 = "<group>"; };
@@ -660,8 +657,6 @@
660657
DFF525301A6235D100D02BA1 /* QNSessionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNSessionManager.m; sourceTree = "<group>"; };
661658
DFF525381A64079B00D02BA1 /* QNSessionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNSessionTest.m; sourceTree = "<group>"; };
662659
DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNFileRecorderTest.m; sourceTree = "<group>"; };
663-
E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_Mac.a"; sourceTree = BUILT_PRODUCTS_DIR; };
664-
F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
665660
FDEA88651DAC10D000D037E5 /* QNAutoZoneTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNAutoZoneTest.m; sourceTree = "<group>"; };
666661
/* End PBXFileReference section */
667662

@@ -670,7 +665,6 @@
670665
isa = PBXFrameworksBuildPhase;
671666
buildActionMask = 2147483647;
672667
files = (
673-
8D0FB78D364BAEE65E20A604 /* libPods-QiniuSDK_iOS.a in Frameworks */,
674668
);
675669
runOnlyForDeploymentPostprocessing = 0;
676670
};
@@ -679,7 +673,6 @@
679673
buildActionMask = 2147483647;
680674
files = (
681675
DF293C9119DB85CB00799011 /* libz.dylib in Frameworks */,
682-
12E9CD5CF6B4132A6ED0D7D4 /* libPods-QiniuSDK_Mac.a in Frameworks */,
683676
);
684677
runOnlyForDeploymentPostprocessing = 0;
685678
};
@@ -689,7 +682,6 @@
689682
files = (
690683
DF0A03231B3BABEC00E3778C /* QiniuSDK_Mac.dylib in Frameworks */,
691684
DF293C9219DB85EB00799011 /* libz.dylib in Frameworks */,
692-
0CD9B2165D33CBCFF01AAE0B /* libPods-QiniuSDK_MacTests.a in Frameworks */,
693685
);
694686
runOnlyForDeploymentPostprocessing = 0;
695687
};
@@ -698,7 +690,6 @@
698690
buildActionMask = 2147483647;
699691
files = (
700692
DF0A03251B3BAC5700E3778C /* libQiniuSDK_iOS.a in Frameworks */,
701-
C275A64FFBE81B9CE7DDC79E /* libPods-QiniuSDK_iOSTests.a in Frameworks */,
702693
);
703694
runOnlyForDeploymentPostprocessing = 0;
704695
};
@@ -916,10 +907,6 @@
916907
A955AABD20BF51BFE5032419 /* Frameworks */ = {
917908
isa = PBXGroup;
918909
children = (
919-
E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */,
920-
24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */,
921-
F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */,
922-
5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */,
923910
);
924911
name = Frameworks;
925912
sourceTree = "<group>";
@@ -1074,6 +1061,7 @@
10741061
316A4B822431C8BA007BF564 /* QNDnsPrefetcherTest.m */,
10751062
DFA9B63E19DFD8C900A15FD1 /* QNEtagTest.m */,
10761063
DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */,
1064+
45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */,
10771065
DF3C504619DD7BA6000F548F /* QNFormUploadTest.m */,
10781066
31259E3524E3D32700CF7531 /* QNGZipTest.m */,
10791067
31C30FAB2852EA7900BFD8F7 /* QNNetworkStatusTest.m */,
@@ -1649,6 +1637,7 @@
16491637
311ADD23257748A700A6E15E /* QNUploadFlowTest.m in Sources */,
16501638
DF437CDF1B243A2C0099587B /* QNUpTokenTest.m in Sources */,
16511639
31DD31D624971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */,
1640+
45CBC6C32AA9B05A00962B47 /* QNFixZoneTest.m in Sources */,
16521641
31A74BCA26E8A89C001EC948 /* QNUplogTest.m in Sources */,
16531642
31A1840E246942E0001D6EEE /* QNComplexUploadSceneTest.m in Sources */,
16541643
DF3C504A19DD7D9F000F548F /* QNResumeUploadTest.m in Sources */,
@@ -1776,6 +1765,7 @@
17761765
311ADD24257748A700A6E15E /* QNUploadFlowTest.m in Sources */,
17771766
DF0A03281B3BAC6E00E3778C /* QNFormUploadTest.m in Sources */,
17781767
31DD31D724971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */,
1768+
45CBC6C42AA9B05A00962B47 /* QNFixZoneTest.m in Sources */,
17791769
31A74BCB26E8A89C001EC948 /* QNUplogTest.m in Sources */,
17801770
31A1840F246942E0001D6EEE /* QNComplexUploadSceneTest.m in Sources */,
17811771
DF0A03291B3BAC6E00E3778C /* QNResumeUploadTest.m in Sources */,
@@ -1948,6 +1938,7 @@
19481938
GENERATE_PKGINFO_FILE = YES;
19491939
INFOPLIST_FILE = "";
19501940
MACOSX_DEPLOYMENT_TARGET = 10.14;
1941+
ONLY_ACTIVE_ARCH = YES;
19511942
PRODUCT_NAME = QiniuSDK_Mac;
19521943
};
19531944
name = Release;
@@ -1984,6 +1975,7 @@
19841975
DEVELOPMENT_TEAM = "";
19851976
GENERATE_INFOPLIST_FILE = YES;
19861977
GENERATE_PKGINFO_FILE = YES;
1978+
ONLY_ACTIVE_ARCH = YES;
19871979
PRODUCT_NAME = QiniuSDK_MacTests;
19881980
PROVISIONING_PROFILE_SPECIFIER = "";
19891981
};
@@ -2009,6 +2001,7 @@
20092001
COPY_PHASE_STRIP = YES;
20102002
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
20112003
GENERATE_PKGINFO_FILE = YES;
2004+
ONLY_ACTIVE_ARCH = YES;
20122005
PRODUCT_NAME = QiniuSDK_iOS;
20132006
SDKROOT = iphoneos;
20142007
};

QiniuSDK/Common/QNFixedZone.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "QNZone.h"
10+
#import "QNDefine.h"
1011

1112
NS_ASSUME_NONNULL_BEGIN
1213

@@ -17,42 +18,42 @@ NS_ASSUME_NONNULL_BEGIN
1718
*
1819
* @return 实例
1920
*/
20-
+ (instancetype)zone0;
21+
+ (instancetype)zone0 kQNDeprecated("use createWithRegionId instead");
2122

2223
/**
2324
* zoneCnEast2 华东-浙江2
2425
*
2526
* @return 实例
2627
*/
27-
+ (instancetype)zoneCnEast2;
28+
+ (instancetype)zoneCnEast2 kQNDeprecated("use createWithRegionId instead");
2829

2930
/**
3031
* zone 1 华北
3132
*
3233
* @return 实例
3334
*/
34-
+ (instancetype)zone1;
35+
+ (instancetype)zone1 kQNDeprecated("use createWithRegionId instead");
3536

3637
/**
3738
* zone 2 华南
3839
*
3940
* @return 实例
4041
*/
41-
+ (instancetype)zone2;
42+
+ (instancetype)zone2 kQNDeprecated("use createWithRegionId instead");
4243

4344
/**
4445
* zone Na0 北美
4546
*
4647
* @return 实例
4748
*/
48-
+ (instancetype)zoneNa0;
49+
+ (instancetype)zoneNa0 kQNDeprecated("use createWithRegionId instead");
4950

5051
/**
5152
* zone As0 新加坡
5253
*
5354
* @return 实例
5455
*/
55-
+ (instancetype)zoneAs0;
56+
+ (instancetype)zoneAs0 kQNDeprecated("use createWithRegionId instead");
5657

5758
/**
5859
* Zone初始化方法
@@ -71,10 +72,20 @@ NS_ASSUME_NONNULL_BEGIN
7172
*/
7273
+ (instancetype)createWithHost:(NSArray<NSString *> *)upList;
7374

75+
/**
76+
* Zone初始化方法
77+
* regionId 参考链接:https://developer.qiniu.com/kodo/1671/region-endpoint-fq
78+
*
79+
* @param regionId 根据区域 ID 创建 Zone
80+
*
81+
* @return Zone 实例
82+
*/
83+
+ (instancetype)createWithRegionId:(NSString *)regionId;
84+
7485
/**
7586
* 获取本地所有固定zone信息
7687
*/
77-
+ (QNFixedZone *)localsZoneInfo;
88+
+ (QNFixedZone *)localsZoneInfo DEPRECATED_ATTRIBUTE;
7889

7990
/**
8091
* 合并区域

QiniuSDK/Common/QNFixedZone.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ + (instancetype)createWithHost:(NSArray<NSString *> *)upList {
120120
return [[QNFixedZone alloc] initWithUpDomainList:upList oldUpList:nil regionId:nil];
121121
}
122122

123+
+ (instancetype)createWithRegionId:(NSString *)regionId {
124+
NSArray *upList = @[
125+
[NSString stringWithFormat:@"upload-%@.qiniup.com", regionId],
126+
[NSString stringWithFormat:@"up-%@.qiniup.com", regionId],
127+
];
128+
return [[QNFixedZone alloc] initWithUpDomainList:upList oldUpList:nil regionId:regionId];
129+
}
130+
123131
- (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)upDomains
124132
regionId:(NSString *)regionId {
125133
return [self createZonesInfo:upDomains oldUpDomains:nil regionId:regionId];

QiniuSDK/Utils/QNDefine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
#define kQNWeakObj(object) __weak typeof(object) weak_##object = object
1515
#define kQNStrongObj(object) __strong typeof(object) object = weak_##object
16+
17+
// 过期
18+
#define kQNDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead)

QiniuSDKTests/QNFixZoneTest.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// QNFixZoneTest.m
3+
// QiniuSDK
4+
//
5+
// Created by yangsen on 2023/9/7.
6+
// Copyright © 2023 Qiniu. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "QNFixedZone.h"
11+
#import "QNZoneInfo.h"
12+
13+
@interface QNFixZoneTest : XCTestCase
14+
15+
@end
16+
17+
@implementation QNFixZoneTest
18+
19+
- (void)setUp {
20+
// Put setup code here. This method is called before the invocation of each test method in the class.
21+
}
22+
23+
- (void)tearDown {
24+
// Put teardown code here. This method is called after the invocation of each test method in the class.
25+
}
26+
27+
- (void)testCreateByRegionId {
28+
QNFixedZone *zone = [QNFixedZone createWithRegionId:@"na0"];
29+
QNZoneInfo *zoneInfo = [zone getZonesInfoWithToken:nil].zonesInfo[0];
30+
31+
XCTAssert([zoneInfo.regionId isEqualToString:@"na0"], @"regionId:%@", zoneInfo.regionId);
32+
XCTAssert([zoneInfo.domains[0] isEqualToString:@"upload-na0.qiniup.com"], @"domains:%@", zoneInfo.domains);
33+
XCTAssert([zoneInfo.domains[1] isEqualToString:@"up-na0.qiniup.com"], @"domains:%@", zoneInfo.domains);
34+
}
35+
36+
@end

0 commit comments

Comments
 (0)