From 21baba3a45a0fb398c2a6a6af852c51792638424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=87=91=E9=93=AD?= <418589912@qq.com> Date: Thu, 4 Feb 2021 10:36:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E6=AC=A1=E6=8F=90=E4=BA=A4=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E4=BB=A5=E4=B8=8B=E5=86=85=E5=AE=B9=EF=BC=9A=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=9B=B4=E6=96=B0=E5=8F=8A=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9A=202.0.0=20=E8=AD=A6=E5=91=8A=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DNRouter.podspec | 2 +- DNRouter/Classes/DNRouter.h | 12 ++--- DNRouter/Classes/DNRouter.m | 49 ++++++++++++------- Example/DNRouter.xcodeproj/project.pbxproj | 16 +++--- .../xcschemes/DNRouter-Example.xcscheme | 2 +- Example/Pods/Pods.xcodeproj/project.pbxproj | 20 ++++---- 6 files changed, 61 insertions(+), 40 deletions(-) diff --git a/DNRouter.podspec b/DNRouter.podspec index eb7d647..17a2cf3 100644 --- a/DNRouter.podspec +++ b/DNRouter.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'DNRouter' - s.version = '1.5.1' + s.version = '2.0.0' s.summary = 'A short description of DNRouter.' # This description is used to generate tags and improve search results. diff --git a/DNRouter/Classes/DNRouter.h b/DNRouter/Classes/DNRouter.h index 741f0ba..df57026 100644 --- a/DNRouter/Classes/DNRouter.h +++ b/DNRouter/Classes/DNRouter.h @@ -18,10 +18,10 @@ extern NSString *const DNRouterParameterCompletion; extern NSString *const DNRouterParameterUserInfo; /// routerParameters内置的几个参数会需要配合上面定义的string使用 -typedef void(^DNRouterHandler)(NSDictionary *routerParameters); +typedef void(^DNRouterHandler)(NSDictionary * __nullable routerParameters); /// 需要返回一个 object,配合 objectForURL: 使用 -typedef id _Nullable (^DNRouterObjectHandler)(NSDictionary *routerParameters); +typedef id _Nullable (^DNRouterObjectHandler)(NSDictionary * __nullable routerParameters); // /// 需要返回一个 object,配合 objectForURL: 使用 typedef void(^DNRouterCompletion)(id __nullable result); @@ -32,12 +32,12 @@ typedef void(^DNRouterCompletion)(id __nullable result); /// 注册 URLPattern 对应的 Handler,在 handler 中可以初始化 VC,然后对 VC 做各种操作 /// @param URLPattern URL键值;带上 scheme,如 renren://beauty/:id /// @param handler 该 block 会传一个字典,包含了注册的 URL 中对应的变量。假如注册的 URL 为 renren://beauty/:id 那么,就会传一个 @{@"id": 4} 这样的字典过来 -+ (void)registerURLPattern:(NSString *__nullable)URLPattern toHandler:(DNRouterHandler)handler; ++ (void)registerURLPattern:(NSString *__nullable)URLPattern toHandler:(DNRouterHandler __nullable)handler; /// 注册 URLPattern 对应的 ObjectHandler,需要返回一个 object 给调用方 /// @param URLPattern URL键值;带上 scheme,如 mgj://beauty/:id /// @param handler 该 block 会传一个字典,包含了注册的 URL 中对应的变量。假如注册的 URL 为 renren://beauty/:id 那么,就会传一个 @{@"id": 4} 这样的字典过来,自带的 key 为 @"url" 和 @"completion" (如果有的话) -+ (void)registerURLPattern:(NSString *__nullable)URLPattern toObjectHandler:(DNRouterObjectHandler)handler; ++ (void)registerURLPattern:(NSString *__nullable)URLPattern toObjectHandler:(DNRouterObjectHandler __nullable)handler; #pragma mark - Cancel /// 取消注册某个 URL Pattern @@ -55,14 +55,14 @@ typedef void(^DNRouterCompletion)(id __nullable result); /// 打开此 URL,同时当操作完成时,执行额外的代码 /// @param URL 带 Scheme 的 URL,如 renren://beauty/4 /// @param completion URL 处理完成后的 callback,完成的判定跟具体的业务相关 -+ (void)openURL:(NSString *__nullable)URL completion:(DNRouterCompletion)completion; ++ (void)openURL:(NSString *__nullable)URL completion:(DNRouterCompletion __nullable)completion; /// 打开此 URL,带上附加信息,同时当操作完成时,执行额外的代码 /// @param URL 带 Scheme 的 URL,如 renren://beauty/4 /// @param userInfo 附加参数 /// @param completion URL 处理完成后的 callback,完成的判定跟具体的业务相关 -+ (void)openURL:(NSString *__nullable)URL withUserInfo:(NSDictionary *__nullable)userInfo completion:(DNRouterCompletion)completion; ++ (void)openURL:(NSString *__nullable)URL withUserInfo:(NSDictionary *__nullable)userInfo completion:(DNRouterCompletion __nullable)completion; #pragma mark - Find diff --git a/DNRouter/Classes/DNRouter.m b/DNRouter/Classes/DNRouter.m index 68742b5..95dabd6 100644 --- a/DNRouter/Classes/DNRouter.m +++ b/DNRouter/Classes/DNRouter.m @@ -42,15 +42,15 @@ + (instancetype)sharedInstance } #pragma mark - Public -+ (void)registerURLPattern:(NSString *__nullable)URLPattern toHandler:(DNRouterHandler)handler { ++ (void)registerURLPattern:(NSString *__nullable)URLPattern toHandler:(DNRouterHandler __nullable)handler { [[self sharedInstance] addURLPattern:URLPattern andHandler:handler]; } -+ (void)registerURLPattern:(NSString *__nullable)URLPattern toObjectHandler:(DNRouterObjectHandler)handler { - [[self sharedInstance] addURLPattern:URLPattern andObjectHandler:handler]; ++ (void)registerURLPattern:(NSString *__nullable)URLPattern toObjectHandler:(DNRouterObjectHandler __nullable)handler { + [[self sharedInstance] addURLPattern:URLPattern andObjectHandler:handler]; } -+ (void)deregisterURLPattern:(NSString *)URLPattern { ++ (void)deregisterURLPattern:(NSString * __nullable)URLPattern { [[self sharedInstance] removeURLPattern:URLPattern]; } @@ -58,17 +58,25 @@ + (void)openURL:(NSString *__nullable)URL { [self openURL:URL completion:nil]; } -+ (void)openURL:(NSString *__nullable)URL completion:(DNRouterCompletion)completion { ++ (void)openURL:(NSString *__nullable)URL completion:(DNRouterCompletion __nullable)completion { [self openURL:URL withUserInfo:nil completion:completion]; } -+ (void)openURL:(NSString *__nullable)URL withUserInfo:(NSDictionary *)userInfo completion:(DNRouterCompletion) completion { ++ (void)openURL:(NSString *__nullable)URL withUserInfo:(NSDictionary *)userInfo completion:(DNRouterCompletion __nullable)completion { + +// if (@available(iOS 9.0, *)) { +// NSString *charactersToEscape = @"?!@#$^&%*+,;='\"`<>()[]{}\\| "; +// NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet]; +// URL = [URL stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters]; +// } else { +// +// } URL = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSMutableDictionary *parameters = [[self sharedInstance] extractParametersFromURL:URL]; [parameters enumerateKeysAndObjectsUsingBlock:^(id key, NSString *obj, BOOL *stop) { if ([obj isKindOfClass:[NSString class]]) { - parameters[key] = [obj stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + parameters[key] = obj.stringByRemovingPercentEncoding; } }]; @@ -87,13 +95,20 @@ + (void)openURL:(NSString *__nullable)URL withUserInfo:(NSDictionary *)userInfo } } -+ (id)objectForURL:(NSString *)URL { ++ (id)objectForURL:(NSString * __nullable)URL { return [self objectForURL:URL withUserInfo:nil]; } -+ (id)objectForURL:(NSString *)URL withUserInfo:(NSDictionary *)userInfo { ++ (id)objectForURL:(NSString * __nullable)URL withUserInfo:(NSDictionary * __nullable)userInfo { DNRouter *router = [DNRouter sharedInstance]; +// if (@available(iOS 9.0, *)) { +// NSString *charactersToEscape = @"?!@#$^&%*+,;='\"`<>()[]{}\\| "; +// NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet]; +// URL = [URL stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters]; +// } else { +// +// } URL = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSMutableDictionary *parameters = [router extractParametersFromURL:URL]; DNRouterObjectHandler handler = parameters[@"block"]; @@ -108,11 +123,11 @@ + (id)objectForURL:(NSString *)URL withUserInfo:(NSDictionary *)userInfo { return nil; } -+ (BOOL)canOpenURL:(NSString *)URL { ++ (BOOL)canOpenURL:(NSString * __nullable)URL { return [[self sharedInstance] extractParametersFromURL:URL] ? YES : NO; } -+ (NSString *)generateURLWithPattern:(NSString *)pattern parameters:(NSArray *)parameters { ++ (NSString *)generateURLWithPattern:(NSString * __nullable)pattern parameters:(NSArray * __nullable)parameters { NSInteger startIndexOfColon = 0; NSMutableArray *placeholders = [NSMutableArray array]; @@ -150,14 +165,14 @@ + (NSString *)generateURLWithPattern:(NSString *)pattern parameters:(NSArray *)p } #pragma mark - Private -- (void)addURLPattern:(NSString *)URLPattern andHandler:(DNRouterHandler)handler{ +- (void)addURLPattern:(NSString * __nullable)URLPattern andHandler:(DNRouterHandler __nullable)handler{ NSMutableDictionary *subRoutes = [self addURLPattern:URLPattern]; if (handler && subRoutes) { subRoutes[@"_"] = [handler copy]; } } -- (NSMutableDictionary *)addURLPattern:(NSString *)URLPattern +- (NSMutableDictionary *)addURLPattern:(NSString * __nullable)URLPattern { NSArray *pathComponents = [self pathComponentsFromURL:URLPattern]; @@ -172,7 +187,7 @@ - (NSMutableDictionary *)addURLPattern:(NSString *)URLPattern return subRoutes; } -- (NSArray*)pathComponentsFromURL:(NSString*)URL +- (NSArray*)pathComponentsFromURL:(NSString * __nullable)URL { NSMutableArray *pathComponents = [NSMutableArray array]; if ([URL rangeOfString:@"://"].location != NSNotFound) { @@ -196,7 +211,7 @@ - (NSArray*)pathComponentsFromURL:(NSString*)URL return [pathComponents copy]; } -- (void)addURLPattern:(NSString *)URLPattern andObjectHandler:(DNRouterObjectHandler)handler +- (void)addURLPattern:(NSString * __nullable)URLPattern andObjectHandler:(DNRouterObjectHandler __nullable)handler { NSMutableDictionary *subRoutes = [self addURLPattern:URLPattern]; if (handler && subRoutes) { @@ -229,7 +244,7 @@ - (void)removeURLPattern:(NSString *)URLPattern } } -- (NSMutableDictionary *)extractParametersFromURL:(NSString *)url +- (NSMutableDictionary *)extractParametersFromURL:(NSString * __nullable)url { NSMutableDictionary* parameters = [NSMutableDictionary dictionary]; @@ -309,7 +324,7 @@ - (NSMutableDictionary *)routes return _routes; } -+ (BOOL)checkIfContainsSpecialCharacter:(NSString *)checkedString { ++ (BOOL)checkIfContainsSpecialCharacter:(NSString * __nullable)checkedString { NSCharacterSet *specialCharactersSet = [NSCharacterSet characterSetWithCharactersInString:specialCharacters]; return [checkedString rangeOfCharacterFromSet:specialCharactersSet].location != NSNotFound; } diff --git a/Example/DNRouter.xcodeproj/project.pbxproj b/Example/DNRouter.xcodeproj/project.pbxproj index b2d84e6..35a910b 100644 --- a/Example/DNRouter.xcodeproj/project.pbxproj +++ b/Example/DNRouter.xcodeproj/project.pbxproj @@ -269,11 +269,11 @@ isa = PBXProject; attributes = { CLASSPREFIX = DN; - LastUpgradeCheck = 1120; + LastUpgradeCheck = 1240; ORGANIZATIONNAME = "418589912@qq.com"; TargetAttributes = { 6003F589195388D20070C39A = { - DevelopmentTeam = W2A55P52D2; + DevelopmentTeam = VKZ5S4BDQY; }; 6003F5AD195388D20070C39A = { TestTargetID = 6003F589195388D20070C39A; @@ -475,6 +475,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -499,7 +500,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -529,6 +530,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -546,7 +548,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -558,10 +560,11 @@ baseConfigurationReference = 55A37A01DF88BDA0CFA91800 /* Pods-DNRouter_Example.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = W2A55P52D2; + DEVELOPMENT_TEAM = VKZ5S4BDQY; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "DNRouter/DNRouter-Prefix.pch"; INFOPLIST_FILE = "DNRouter/DNRouter-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -574,10 +577,11 @@ baseConfigurationReference = F8B154ED6EC0FD393C1C2500 /* Pods-DNRouter_Example.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = W2A55P52D2; + DEVELOPMENT_TEAM = VKZ5S4BDQY; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "DNRouter/DNRouter-Prefix.pch"; INFOPLIST_FILE = "DNRouter/DNRouter-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MODULE_NAME = ExampleApp; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Example/DNRouter.xcodeproj/xcshareddata/xcschemes/DNRouter-Example.xcscheme b/Example/DNRouter.xcodeproj/xcshareddata/xcschemes/DNRouter-Example.xcscheme index 5e36e41..c43b1fa 100644 --- a/Example/DNRouter.xcodeproj/xcshareddata/xcschemes/DNRouter-Example.xcscheme +++ b/Example/DNRouter.xcodeproj/xcshareddata/xcschemes/DNRouter-Example.xcscheme @@ -1,6 +1,6 @@