├── .gitignore ├── DCURLRouter.podspec ├── DCURLRouter ├── DCSingleton.h ├── DCURLNavgation.h ├── DCURLNavgation.m ├── DCURLRouter.h ├── DCURLRouter.m ├── DCURLRouter.plist ├── UIViewController+DCURLRouter.h └── UIViewController+DCURLRouter.m ├── DCURLRouterDemo ├── DCURLRouterDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── DCURLRouterDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── ZHEditorSettingIconNormal.imageset │ │ ├── Contents.json │ │ ├── ZHEditorSettingIconNormal@2x.png │ │ └── ZHEditorSettingIconNormal@3x.png │ └── ZHEditorSettingIconOpen.imageset │ │ ├── Contents.json │ │ ├── ZHEditorSettingIconOpen@2x.png │ │ └── ZHEditorSettingIconOpen@3x.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── FiveViewController.h │ ├── FiveViewController.m │ ├── FourViewController.h │ ├── FourViewController.m │ ├── Info.plist │ ├── OneChildView.h │ ├── OneChildView.m │ ├── OneViewController.h │ ├── OneViewController.m │ ├── ThreeViewController.h │ ├── ThreeViewController.m │ ├── TwoViewController.h │ ├── TwoViewController.m │ ├── WebViewController.h │ ├── WebViewController.m │ ├── XibViewController.h │ ├── XibViewController.m │ ├── XibViewController.xib │ └── main.m ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | .DS_Store 6 | 7 | ## Build generated 8 | build/ 9 | DerivedData/ 10 | 11 | ## Various settings 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata/ 21 | 22 | ## Other 23 | *.moved-aside 24 | *.xcuserstate 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | *.dSYM.zip 30 | *.dSYM 31 | 32 | # CocoaPods 33 | # 34 | # We recommend against adding the Pods directory to your .gitignore. However 35 | # you should judge for yourself, the pros and cons are mentioned at: 36 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 37 | # 38 | # Pods/ 39 | 40 | # Carthage 41 | # 42 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 43 | # Carthage/Checkouts 44 | 45 | Carthage/Build 46 | 47 | # fastlane 48 | # 49 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 50 | # screenshots whenever they are needed. 51 | # For more information about the recommended setup visit: 52 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 53 | 54 | fastlane/report.xml 55 | fastlane/screenshots 56 | 57 | #Code Injection 58 | # 59 | # After new code Injection tools there's a generated folder /iOSInjectionProject 60 | # https://github.com/johnno1962/injectionforxcode 61 | 62 | iOSInjectionProject/ 63 | -------------------------------------------------------------------------------- /DCURLRouter.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | 4 | s.name = "DCURLRouter" 5 | s.version = "0.81" 6 | s.summary = "Use custom URL to change ViewController." 7 | 8 | s.description = "Use custom URL to push and modal viewController. you can pop or dismiss several controller at the same time.you can modal a controller with a Navigation Controller…" 9 | 10 | s.homepage = "https://github.com/DarielChen/DCURLRouter" 11 | 12 | s.license = "MIT" 13 | 14 | s.author = { "DarielChen" => "chendariel@gmail.com" } 15 | 16 | s.platform = :ios 17 | 18 | s.source = { :git => "https://github.com/DarielChen/DCURLRouter.git", :tag => "#{s.version}" } 19 | 20 | s.source_files = "DCURLRouter/*{h,m}" 21 | s.exclude_files = "DCURLRouter/DCURLRouter.plist" 22 | 23 | s.framework = "UIKit" 24 | s.requires_arc = true 25 | 26 | end 27 | -------------------------------------------------------------------------------- /DCURLRouter/DCSingleton.h: -------------------------------------------------------------------------------- 1 | // 2 | // DCSingleton.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 单例宏 8 | 9 | // .h文件 10 | #define DCSingletonH(name) + (instancetype)shared##name; 11 | // .m文件 12 | #define DCSingletonM(name) \ 13 | static id _instance; \ 14 | \ 15 | + (instancetype)allocWithZone:(struct _NSZone *)zone \ 16 | { \ 17 | static dispatch_once_t onceToken; \ 18 | dispatch_once(&onceToken, ^{ \ 19 | _instance = [super allocWithZone:zone]; \ 20 | }); \ 21 | return _instance; \ 22 | } \ 23 | \ 24 | + (instancetype)shared##name \ 25 | { \ 26 | static dispatch_once_t onceToken; \ 27 | dispatch_once(&onceToken, ^{ \ 28 | _instance = [[self alloc] init]; \ 29 | }); \ 30 | return _instance; \ 31 | } \ 32 | \ 33 | - (id)copyWithZone:(NSZone *)zone \ 34 | { \ 35 | return _instance; \ 36 | } -------------------------------------------------------------------------------- /DCURLRouter/DCURLNavgation.h: -------------------------------------------------------------------------------- 1 | // 2 | // DCURLNavgation.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 控制器 导航控制器管理 8 | 9 | #import 10 | #import "DCSingleton.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface DCURLNavgation : NSObject 15 | DCSingletonH(DCURLNavgation) 16 | 17 | /** 18 | * 返回当前控制器 19 | */ 20 | - (UIViewController*)currentViewController; 21 | 22 | /** 23 | * 返回当前的导航控制器 24 | */ 25 | - (UINavigationController*)currentNavigationViewController; 26 | 27 | 28 | 29 | + (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated replace:(BOOL)replace; 30 | + (void)presentViewController:(UIViewController *)viewController animated: (BOOL)flag completion:(void (^ __nullable)(void))completion; 31 | 32 | + (void)popTwiceViewControllerAnimated:(BOOL)animated; 33 | + (void)popViewControllerWithTimes:(NSUInteger)times animated:(BOOL)animated; 34 | + (void)popToRootViewControllerAnimated:(BOOL)animated; 35 | 36 | 37 | + (void)dismissTwiceViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 38 | + (void)dismissViewControllerWithTimes:(NSUInteger)times animated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 39 | + (void)dismissToRootViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 40 | 41 | NS_ASSUME_NONNULL_END 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /DCURLRouter/DCURLNavgation.m: -------------------------------------------------------------------------------- 1 | // 2 | // DCURLNavgation.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "DCURLNavgation.h" 10 | 11 | #ifdef DEBUG 12 | # define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); 13 | #else 14 | # define DLog(...) 15 | #endif 16 | 17 | @implementation DCURLNavgation 18 | DCSingletonM(DCURLNavgation) 19 | 20 | - (UIViewController*)currentViewController { 21 | UIViewController* rootViewController = self.applicationDelegate.window.rootViewController; 22 | return [self currentViewControllerFrom:rootViewController]; 23 | } 24 | 25 | - (UINavigationController*)currentNavigationViewController { 26 | UIViewController* currentViewController = self.currentViewController; 27 | return currentViewController.navigationController; 28 | } 29 | 30 | - (id)applicationDelegate { 31 | return [UIApplication sharedApplication].delegate; 32 | } 33 | 34 | + (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated replace:(BOOL)replace 35 | { 36 | if (!viewController) { 37 | DLog(@"请添加与url相匹配的控制器到plist文件中,或者协议头可能写错了!"); 38 | } 39 | else { 40 | if([viewController isKindOfClass:[UINavigationController class]]) { 41 | [DCURLNavgation setRootViewController:viewController]; 42 | } // 如果是导航控制器直接设置为根控制器 43 | else { 44 | UINavigationController *navigationController = [DCURLNavgation sharedDCURLNavgation].currentNavigationViewController; 45 | if (navigationController) { // 导航控制器存在 46 | // In case it should replace, look for the last UIViewController on the UINavigationController, if it's of the same class, replace it with a new one. 47 | if (replace && [navigationController.viewControllers.lastObject isKindOfClass:[viewController class]]) { 48 | 49 | NSArray *viewControllers = [navigationController.viewControllers subarrayWithRange:NSMakeRange(0, navigationController.viewControllers.count-1)]; 50 | [navigationController setViewControllers:[viewControllers arrayByAddingObject:viewController] animated:animated]; 51 | } // 切换当前导航控制器 需要把原来的子控制器都取出来重新添加 52 | else { 53 | [navigationController pushViewController:viewController animated:animated]; 54 | } // 进行push 55 | } 56 | else { 57 | navigationController = [[UINavigationController alloc]initWithRootViewController:viewController]; 58 | [DCURLNavgation sharedDCURLNavgation].applicationDelegate.window.rootViewController = navigationController; 59 | } // 如果导航控制器不存在,就会创建一个新的,设置为根控制器 60 | } 61 | } 62 | } 63 | 64 | + (void)presentViewController:(UIViewController *)viewController animated: (BOOL)flag completion:(void (^ __nullable)(void))completion 65 | { 66 | if (!viewController) { 67 | DLog(@"请添加与url相匹配的控制器到plist文件中,或者协议头可能写错了!"); 68 | }else { 69 | UIViewController *currentViewController = [[DCURLNavgation sharedDCURLNavgation] currentViewController]; 70 | if (currentViewController) { // 当前控制器存在 71 | [currentViewController presentViewController:viewController animated:flag completion:completion]; 72 | } else { // 将控制器设置为根控制器 73 | [DCURLNavgation sharedDCURLNavgation].applicationDelegate.window.rootViewController = viewController; 74 | } 75 | } 76 | } 77 | 78 | // 设置为根控制器 79 | + (void)setRootViewController:(UIViewController *)viewController 80 | { 81 | [DCURLNavgation sharedDCURLNavgation].applicationDelegate.window.rootViewController = viewController; 82 | } 83 | 84 | // 通过递归拿到当前控制器 85 | - (UIViewController*)currentViewControllerFrom:(UIViewController*)viewController { 86 | if ([viewController isKindOfClass:[UINavigationController class]]) { 87 | UINavigationController* navigationController = (UINavigationController *)viewController; 88 | return [self currentViewControllerFrom:navigationController.viewControllers.lastObject]; 89 | } // 如果传入的控制器是导航控制器,则返回最后一个 90 | else if([viewController isKindOfClass:[UITabBarController class]]) { 91 | UITabBarController* tabBarController = (UITabBarController *)viewController; 92 | return [self currentViewControllerFrom:tabBarController.selectedViewController]; 93 | } // 如果传入的控制器是tabBar控制器,则返回选中的那个 94 | else if(viewController.presentedViewController != nil) { 95 | return [self currentViewControllerFrom:viewController.presentedViewController]; 96 | } // 如果传入的控制器发生了modal,则就可以拿到modal的那个控制器 97 | else { 98 | return viewController; 99 | } 100 | } 101 | 102 | + (void)popTwiceViewControllerAnimated:(BOOL)animated { 103 | [DCURLNavgation popViewControllerWithTimes:2 animated:YES]; 104 | } 105 | 106 | + (void)popViewControllerWithTimes:(NSUInteger)times animated:(BOOL)animated { 107 | 108 | UIViewController *currentViewController = [[DCURLNavgation sharedDCURLNavgation] currentViewController]; 109 | NSUInteger count = currentViewController.navigationController.viewControllers.count; 110 | if(currentViewController){ 111 | if(currentViewController.navigationController) { 112 | if (count > times){ 113 | [currentViewController.navigationController popToViewController:[currentViewController.navigationController.viewControllers objectAtIndex:count-1-times] animated:animated]; 114 | }else { // 如果times大于控制器的数量 115 | DLog(@"确定可以pop掉那么多控制器?"); 116 | } 117 | } 118 | } 119 | } 120 | 121 | + (void)popToRootViewControllerAnimated:(BOOL)animated { 122 | UIViewController *currentViewController = [[DCURLNavgation sharedDCURLNavgation] currentViewController]; 123 | NSUInteger count = currentViewController.navigationController.viewControllers.count; 124 | [DCURLNavgation popViewControllerWithTimes:count-1 animated:YES]; 125 | } 126 | 127 | 128 | + (void)dismissTwiceViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion { 129 | [self dismissViewControllerWithTimes:2 animated:YES completion:completion]; 130 | } 131 | 132 | 133 | + (void)dismissViewControllerWithTimes:(NSUInteger)times animated: (BOOL)flag completion: (void (^ __nullable)(void))completion { 134 | UIViewController *rootVC = [[DCURLNavgation sharedDCURLNavgation] currentViewController]; 135 | 136 | if (rootVC) { 137 | while (times > 0) { 138 | rootVC = rootVC.presentingViewController; 139 | times -= 1; 140 | } 141 | [rootVC dismissViewControllerAnimated:YES completion:completion]; 142 | } 143 | 144 | if (!rootVC.presentedViewController) { 145 | DLog(@"确定能dismiss掉这么多控制器?"); 146 | } 147 | } 148 | 149 | 150 | + (void)dismissToRootViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion { 151 | UIViewController *currentViewController = [[DCURLNavgation sharedDCURLNavgation] currentViewController]; 152 | UIViewController *rootVC = currentViewController; 153 | while (rootVC.presentingViewController) { 154 | rootVC = rootVC.presentingViewController; 155 | } 156 | [rootVC dismissViewControllerAnimated:YES completion:completion]; 157 | } 158 | 159 | @end 160 | -------------------------------------------------------------------------------- /DCURLRouter/DCURLRouter.h: -------------------------------------------------------------------------------- 1 | // 2 | // DCURLRouter.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 核心类 通过调用类方法实现自定义URL跳转 8 | 9 | #import 10 | #import "DCSingleton.h" 11 | #import "UIViewController+DCURLRouter.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface DCURLRouter : NSObject 16 | DCSingletonH(DCURLRouter) 17 | 18 | /** 19 | * 加载plist文件中的URL配置信息 20 | * 21 | * @param pistName plist文件名称,不用加后缀 22 | */ 23 | + (void)loadConfigDictFromPlist:(NSString *)pistName; 24 | 25 | #pragma mark -------- 拿到导航控制器 和当前控制器 -------- 26 | 27 | /** 返回当前控制器 */ 28 | - (UIViewController*)currentViewController; 29 | 30 | /** 返回当前控制器的导航控制器 */ 31 | - (UINavigationController*)currentNavigationViewController; 32 | 33 | #pragma mark -------- push控制器 -------- 34 | /** 35 | * push控制器 同系统的 36 | * 37 | * @param viewController 目标控制器 38 | */ 39 | + (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; 40 | 41 | /** 42 | * push控制器 类似系统的 43 | * 44 | * @param viewController 目标控制器 45 | * @param replace 如果当前控制器和要push的控制器是同一个,可以将replace设置为Yes,进行替换.同一个才能替换哦! 46 | */ 47 | + (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated replace:(BOOL)replace; 48 | 49 | /** 50 | * push控制器 51 | * 52 | * @param urlString 自定义的URL,可以拼接参数 53 | */ 54 | + (void)pushURLString:(NSString *)urlString animated:(BOOL)animated; 55 | 56 | /** 57 | * push控制器 58 | * 59 | * @param urlString 自定义URL,也可以拼接参数,但会被下面的query替换掉 60 | * @param query 存放参数 61 | */ 62 | + (void)pushURLString:(NSString *)urlString query:(NSDictionary *)query animated:(BOOL)animated; 63 | 64 | /** 65 | * push控制器 66 | * 67 | * @param urlString 自定义的URL,可以拼接参数 68 | * @param replace 如果当前控制器和要push的控制器是同一个,可以将replace设置为Yes,进行替换.同一个才能替换哦! 69 | */ 70 | + (void)pushURLString:(NSString *)urlString animated:(BOOL)animated replace:(BOOL)replace; 71 | 72 | /** 73 | * push控制器 74 | * 75 | * @param urlString 自定义URL,也可以拼接参数,但会被下面的query替换掉 76 | * @param query 存放参数 77 | * @param replace 如果当前控制器和要push的控制器是同一个,可以将replace设置为Yes,进行替换.同一个才能替换哦! 78 | */ 79 | + (void)pushURLString:(NSString *)urlString query:(NSDictionary *)query animated:(BOOL)animated replace:(BOOL)replace; 80 | 81 | #pragma mark -------- pop控制器 -------- 82 | 83 | /** pop掉一层控制器 */ 84 | + (void)popViewControllerAnimated:(BOOL)animated; 85 | /** pop掉两层控制器 */ 86 | + (void)popTwiceViewControllerAnimated:(BOOL)animated; 87 | /** pop掉times层控制器 */ 88 | + (void)popViewControllerWithTimes:(NSUInteger)times animated:(BOOL)animated; 89 | /** pop到根层控制器 */ 90 | + (void)popToRootViewControllerAnimated:(BOOL)animated; 91 | 92 | #pragma mark -------- modal控制器 -------- 93 | 94 | /** 95 | * modal控制器 96 | * 97 | * @param viewControllerToPresent 目标控制器 98 | */ 99 | + (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion; 100 | 101 | /** 102 | * modal控制器 103 | * 104 | * @param viewControllerToPresent 目标控制器 105 | * @param classType 需要添加的导航控制器 eg.[UINavigationController class] 106 | */ 107 | + (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag withNavigationClass:(Class)classType completion:(void (^ __nullable)(void))completion; 108 | 109 | /** 110 | * modal控制器 111 | * 112 | * @param urlString 自定义的URL,可以拼接参数 113 | */ 114 | + (void)presentURLString:(NSString *)urlString animated:(BOOL)animated completion:(void (^ __nullable)(void))completion; 115 | 116 | /** 117 | * modal控制器 118 | * 119 | * @param urlString 自定义URL,也可以拼接参数,但会被下面的query替换掉 120 | * @param query 存放参数 121 | */ 122 | + (void)presentURLString:(NSString *)urlString query:(NSDictionary *)query animated:(BOOL)animated completion:(void (^ __nullable)(void))completion; 123 | 124 | /** 125 | * modal控制器,并且给modal出来的控制器添加一个导航控制器 126 | * 127 | * @param urlString 自定义的URL,可以拼接参数 128 | * @param classType 需要添加的导航控制器 eg.[UINavigationController class] 129 | */ 130 | + (void)presentURLString:(NSString *)urlString animated:(BOOL)animated withNavigationClass:(Class)classType completion:(void (^ __nullable)(void))completion; 131 | 132 | /** 133 | * modal控制器,并且给modal出来的控制器添加一个导航控制器 134 | * 135 | * @param urlString 自定义URL,也可以拼接参数,但会被下面的query替换掉 136 | * @param query 存放参数 137 | * @param clazz 需要添加的导航控制器 eg.[UINavigationController class] 138 | */ 139 | + (void)presentURLString:(NSString *)urlString query:(NSDictionary *)query animated:(BOOL)animated withNavigationClass:(Class)clazz completion:(void (^ __nullable)(void))completion; 140 | 141 | #pragma mark -------- dismiss控制器 -------- 142 | /** dismiss掉1层控制器 */ 143 | + (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 144 | /** dismiss掉2层控制器 */ 145 | + (void)dismissTwiceViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 146 | /** dismiss掉times层控制器 */ 147 | + (void)dismissViewControllerWithTimes:(NSUInteger)times animated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 148 | /** dismiss到根层控制器 */ 149 | + (void)dismissToRootViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 150 | 151 | NS_ASSUME_NONNULL_END 152 | @end 153 | -------------------------------------------------------------------------------- /DCURLRouter/DCURLRouter.m: -------------------------------------------------------------------------------- 1 | // 2 | // DCURLRouter.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "DCURLRouter.h" 10 | #import "DCURLNavgation.h" 11 | 12 | #ifdef DEBUG 13 | # define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); 14 | #else 15 | # define DLog(...) 16 | #endif 17 | 18 | @interface DCURLRouter() 19 | 20 | /** 存储读取的plist文件数据 */ 21 | @property(nonatomic,strong) NSDictionary *configDict; 22 | 23 | @end 24 | 25 | @implementation DCURLRouter 26 | DCSingletonM(DCURLRouter) 27 | 28 | + (void)loadConfigDictFromPlist:(NSString *)pistName { 29 | 30 | NSString *path = [[NSBundle mainBundle] pathForResource:pistName ofType:nil]; 31 | NSDictionary *configDict = [NSDictionary dictionaryWithContentsOfFile:path]; 32 | 33 | if (configDict) { 34 | [DCURLRouter sharedDCURLRouter].configDict = configDict; 35 | }else { 36 | DLog(@"请按照说明添加对应的plist文件"); 37 | } 38 | } 39 | 40 | + (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { 41 | 42 | [DCURLNavgation pushViewController:viewController animated:animated replace:NO]; 43 | } 44 | 45 | + (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated replace:(BOOL)replace { 46 | [DCURLNavgation pushViewController:viewController animated:animated replace:replace]; 47 | } 48 | 49 | + (void)pushURLString:(NSString *)urlString animated:(BOOL)animated { 50 | 51 | UIViewController *viewController = [UIViewController initFromString:urlString fromConfig:[DCURLRouter sharedDCURLRouter].configDict]; 52 | [DCURLNavgation pushViewController:viewController animated:animated replace:NO]; 53 | } 54 | 55 | + (void)pushURLString:(NSString *)urlString query:(NSDictionary *)query animated:(BOOL)animated{ 56 | UIViewController *viewController = [UIViewController initFromString:urlString withQuery:query fromConfig:[DCURLRouter sharedDCURLRouter].configDict]; 57 | [DCURLNavgation pushViewController:viewController animated:animated replace:NO]; 58 | } 59 | 60 | + (void)pushURLString:(NSString *)urlString animated:(BOOL)animated replace:(BOOL)replace{ 61 | UIViewController *viewController = [UIViewController initFromString:urlString fromConfig:[DCURLRouter sharedDCURLRouter].configDict]; 62 | [DCURLNavgation pushViewController:viewController animated:YES replace:replace]; 63 | } 64 | 65 | 66 | + (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion { 67 | [DCURLNavgation presentViewController:viewControllerToPresent animated:flag completion:completion]; 68 | } 69 | 70 | + (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag withNavigationClass:(Class)classType completion:(void (^ __nullable)(void))completion { 71 | 72 | if ([classType isSubclassOfClass:[UINavigationController class]]) { 73 | UINavigationController *nav = [[classType alloc]initWithRootViewController:viewControllerToPresent]; 74 | [DCURLNavgation presentViewController:nav animated:flag completion:completion]; 75 | } 76 | } 77 | 78 | 79 | + (void)presentURLString:(NSString *)urlString animated:(BOOL)animated completion:(void (^ __nullable)(void))completion{ 80 | UIViewController *viewController = [UIViewController initFromString:urlString fromConfig:[DCURLRouter sharedDCURLRouter].configDict]; 81 | [DCURLNavgation presentViewController:viewController animated:animated completion:completion]; 82 | } 83 | 84 | 85 | + (void)presentURLString:(NSString *)urlString query:(NSDictionary *)query animated:(BOOL)animated completion:(void (^ __nullable)(void))completion{ 86 | UIViewController *viewController = [UIViewController initFromString:urlString withQuery:query fromConfig:[DCURLRouter sharedDCURLRouter].configDict]; 87 | [DCURLNavgation presentViewController:viewController animated:animated completion:completion]; 88 | } 89 | 90 | 91 | + (void)pushURLString:(NSString *)urlString query:(NSDictionary *)query animated:(BOOL)animated replace:(BOOL)replace{ 92 | UIViewController *viewController = [UIViewController initFromString:urlString withQuery:query fromConfig:[DCURLRouter sharedDCURLRouter].configDict]; 93 | [DCURLNavgation pushViewController:viewController animated:animated replace:replace]; 94 | } 95 | 96 | 97 | + (void)presentURLString:(NSString *)urlString animated:(BOOL)animated withNavigationClass:(Class)classType completion:(void (^ __nullable)(void))completion{ 98 | 99 | UIViewController *viewController = [UIViewController initFromString:urlString fromConfig:[DCURLRouter sharedDCURLRouter].configDict]; 100 | if ([classType isSubclassOfClass:[UINavigationController class]]) { 101 | UINavigationController *nav = [[classType alloc]initWithRootViewController:viewController]; 102 | [DCURLNavgation presentViewController:nav animated:animated completion:completion]; 103 | } 104 | } 105 | 106 | + (void)presentURLString:(NSString *)urlString query:(NSDictionary *)query animated:(BOOL)animated withNavigationClass:(Class)clazz completion:(void (^ __nullable)(void))completion{ 107 | UIViewController *viewController = [UIViewController initFromString:urlString withQuery:query fromConfig:[DCURLRouter sharedDCURLRouter].configDict]; 108 | if ([clazz isSubclassOfClass:[UINavigationController class]]) { 109 | UINavigationController *nav = [[clazz alloc]initWithRootViewController:viewController]; 110 | [DCURLNavgation presentViewController:nav animated:animated completion:completion]; 111 | } 112 | } 113 | 114 | + (void)popViewControllerAnimated:(BOOL)animated { 115 | [DCURLNavgation popViewControllerWithTimes:1 animated:animated]; 116 | } 117 | 118 | + (void)popTwiceViewControllerAnimated:(BOOL)animated { 119 | [DCURLNavgation popTwiceViewControllerAnimated:animated]; 120 | } 121 | + (void)popViewControllerWithTimes:(NSUInteger)times animated:(BOOL)animated { 122 | [DCURLNavgation popViewControllerWithTimes:times animated:animated]; 123 | } 124 | + (void)popToRootViewControllerAnimated:(BOOL)animated { 125 | [DCURLNavgation popToRootViewControllerAnimated:animated]; 126 | } 127 | 128 | 129 | + (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion { 130 | [DCURLNavgation dismissViewControllerWithTimes:1 animated:flag completion:completion]; 131 | } 132 | + (void)dismissTwiceViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion { 133 | [DCURLNavgation dismissTwiceViewControllerAnimated:flag completion:completion]; 134 | } 135 | 136 | + (void)dismissViewControllerWithTimes:(NSUInteger)times animated: (BOOL)flag completion: (void (^ __nullable)(void))completion { 137 | [DCURLNavgation dismissViewControllerWithTimes:times animated:flag completion:completion]; 138 | } 139 | 140 | + (void)dismissToRootViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion { 141 | [DCURLNavgation dismissToRootViewControllerAnimated:flag completion:completion]; 142 | } 143 | 144 | - (UIViewController*)currentViewController { 145 | return [DCURLNavgation sharedDCURLNavgation].currentViewController; 146 | } 147 | 148 | - (UINavigationController*)currentNavigationViewController { 149 | return [DCURLNavgation sharedDCURLNavgation].currentNavigationViewController; 150 | } 151 | 152 | 153 | @end 154 | -------------------------------------------------------------------------------- /DCURLRouter/DCURLRouter.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | http 6 | WebViewController 7 | https 8 | WebViewController 9 | dariel 10 | 11 | dariel://twoitem 12 | TwoViewController 13 | dariel://threeitem 14 | ThreeViewController 15 | dariel://fouritem 16 | FourViewController 17 | dariel://fiveitem 18 | FiveViewController 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /DCURLRouter/UIViewController+DCURLRouter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+DCURLRouter.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | @interface UIViewController (DCURLRouter) 13 | 14 | /** 跳转后控制器能拿到的url */ 15 | @property(nonatomic, strong) NSURL *originUrl; 16 | 17 | /** url路径 */ 18 | @property(nonatomic,copy) NSString *path; 19 | 20 | /** 跳转后控制器能拿到的参数 */ 21 | @property(nonatomic,strong) NSDictionary *params; 22 | 23 | /** 回调block */ 24 | @property (nonatomic, strong) void(^valueBlock)(id value); 25 | 26 | // 根据参数创建控制器 27 | + (UIViewController *)initFromString:(NSString *)urlString fromConfig:(NSDictionary *)configDict; 28 | // 根据参数创建控制器 29 | + (UIViewController *)initFromString:(NSString *)urlString withQuery:(NSDictionary *)query fromConfig:(NSDictionary *)configDict; 30 | 31 | 32 | NS_ASSUME_NONNULL_END 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /DCURLRouter/UIViewController+DCURLRouter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewController+DCURLRouter.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "UIViewController+DCURLRouter.h" 10 | #import 11 | 12 | static char URLoriginUrl; 13 | static char URLpath; 14 | static char URLparams; 15 | 16 | static char dataCallBack; 17 | 18 | @implementation UIViewController (DCURLRouter) 19 | 20 | 21 | - (void)setOriginUrl:(NSURL *)originUrl { 22 | // 为分类设置属性值 23 | objc_setAssociatedObject(self, &URLoriginUrl, 24 | originUrl, 25 | OBJC_ASSOCIATION_RETAIN_NONATOMIC); 26 | } 27 | 28 | - (NSURL *)originUrl { 29 | // 获取分类的属性值 30 | return objc_getAssociatedObject(self, &URLoriginUrl); 31 | } 32 | 33 | - (void)setValueBlock:(void (^)(id _Nonnull))valueBlock { 34 | objc_setAssociatedObject(self, &dataCallBack, 35 | valueBlock, 36 | OBJC_ASSOCIATION_RETAIN_NONATOMIC); 37 | } 38 | 39 | - (void (^)(id _Nonnull))valueBlock { 40 | return objc_getAssociatedObject(self, &dataCallBack); 41 | } 42 | 43 | - (NSString *)path { 44 | return objc_getAssociatedObject(self, &URLpath); 45 | } 46 | 47 | - (void)setPath:(NSURL *)path{ 48 | objc_setAssociatedObject(self, &URLpath, 49 | path, 50 | OBJC_ASSOCIATION_RETAIN_NONATOMIC); 51 | } 52 | 53 | - (NSDictionary *)params { 54 | return objc_getAssociatedObject(self, &URLparams); 55 | } 56 | 57 | - (void)setParams:(NSDictionary *)params{ 58 | objc_setAssociatedObject(self, &URLparams, 59 | params, 60 | OBJC_ASSOCIATION_RETAIN_NONATOMIC); 61 | } 62 | 63 | + (UIViewController *)initFromString:(NSString *)urlString fromConfig:(NSDictionary *)configDict{ 64 | 65 | // 支持对中文字符的编码 66 | NSString *encodeStr = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; 67 | return [UIViewController initFromURL:[NSURL URLWithString:encodeStr] withQuery:nil fromConfig:configDict]; 68 | } 69 | 70 | + (UIViewController *)initFromString:(NSString *)urlString withQuery:(NSDictionary *)query fromConfig:(NSDictionary *)configDict{ 71 | 72 | // 支持对中文字符的编码 73 | NSString *encodeStr = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; 74 | return [UIViewController initFromURL:[NSURL URLWithString:encodeStr] withQuery:query fromConfig:configDict] ; 75 | } 76 | 77 | - (void)open:(NSURL *)url withQuery:(NSDictionary *)query{ 78 | self.path = [url path]; 79 | self.originUrl = url; 80 | if (query) { // 如果自定义url后面有拼接参数,而且又通过query传入了参数,那么优先query传入了参数 81 | self.params = query; 82 | }else { 83 | self.params = [self paramsURL:url]; 84 | } 85 | } 86 | 87 | + (UIViewController *)initFromURL:(NSURL *)url withQuery:(NSDictionary *)query fromConfig:(NSDictionary *)configDict 88 | { 89 | UIViewController *VC = nil; 90 | NSString *home; 91 | if(url.path == nil){ // 处理url,去掉有可能会拼接的参数 92 | home = [NSString stringWithFormat:@"%@://%@", url.scheme, url.host]; 93 | }else{ 94 | home = [NSString stringWithFormat:@"%@://%@%@", url.scheme, url.host,url.path]; 95 | } 96 | if([configDict.allKeys containsObject:url.scheme]){ // 字典中的所有的key是否包含传入的协议头 97 | id config = [configDict objectForKey:url.scheme]; // 根据协议头取出值 98 | Class class = nil; 99 | if([config isKindOfClass:[NSString class]]){ //当协议头是http https的情况 100 | class = NSClassFromString(config); 101 | }else if([config isKindOfClass:[NSDictionary class]]){ // 自定义的url情况 102 | NSDictionary *dict = (NSDictionary *)config; 103 | if([dict.allKeys containsObject:home]){ 104 | class = NSClassFromString([dict objectForKey:home]); // 根据key拿到对应的控制器名称 105 | if (class == nil) { // 兼容swift,字符串转类名的时候前面加上命名空间 106 | NSString *spaceName = [NSBundle mainBundle].infoDictionary[@"CFBundleExecutable"]; 107 | class = NSClassFromString([NSString stringWithFormat:@"%@.%@",spaceName,[dict objectForKey:home]]); 108 | } 109 | } 110 | } 111 | if(class !=nil){ 112 | VC = [[class alloc]init]; 113 | if([VC respondsToSelector:@selector(open:withQuery:)]){ 114 | [VC open:url withQuery:query]; 115 | } 116 | } 117 | // 处理网络地址的情况 118 | if ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"]) { 119 | class = NSClassFromString([configDict objectForKey:url.scheme]); 120 | VC.params = @{@"urlStr": [url absoluteString]}; 121 | } 122 | } 123 | return VC; 124 | } 125 | 126 | // 将url的参数部分转化成字典 127 | - (NSDictionary *)paramsURL:(NSURL *)url { 128 | 129 | NSMutableDictionary* pairs = [NSMutableDictionary dictionary]; 130 | if (NSNotFound != [url.absoluteString rangeOfString:@"?"].location) { 131 | NSString *paramString = [url.absoluteString substringFromIndex: 132 | ([url.absoluteString rangeOfString:@"?"].location + 1)]; 133 | 134 | NSCharacterSet* delimiterSet = [NSCharacterSet characterSetWithCharactersInString:@"&"]; 135 | NSScanner* scanner = [[NSScanner alloc] initWithString:paramString]; 136 | while (![scanner isAtEnd]) { 137 | NSString* pairString = nil; 138 | [scanner scanUpToCharactersFromSet:delimiterSet intoString:&pairString]; 139 | [scanner scanCharactersFromSet:delimiterSet intoString:NULL]; 140 | NSArray* kvPair = [pairString componentsSeparatedByString:@"="]; 141 | if (kvPair.count == 2) { 142 | NSString* key = [[kvPair objectAtIndex:0] stringByRemovingPercentEncoding]; 143 | NSString* value = [[kvPair objectAtIndex:1] stringByRemovingPercentEncoding]; 144 | [pairs setValue:value forKey:key]; 145 | } 146 | } 147 | } 148 | 149 | return [NSDictionary dictionaryWithDictionary:pairs]; 150 | } 151 | 152 | @end 153 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 15143CAB1D66AB24006BD05D /* OneChildView.m in Sources */ = {isa = PBXBuildFile; fileRef = 15143CAA1D66AB24006BD05D /* OneChildView.m */; }; 11 | 1526ABF01D6B316D0083C658 /* XibViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1526ABEE1D6B316D0083C658 /* XibViewController.m */; }; 12 | 1526ABF11D6B316D0083C658 /* XibViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1526ABEF1D6B316D0083C658 /* XibViewController.xib */; }; 13 | 1550809A1F21F4D4007078E5 /* DCURLNavgation.m in Sources */ = {isa = PBXBuildFile; fileRef = 155080941F21F4D4007078E5 /* DCURLNavgation.m */; }; 14 | 1550809B1F21F4D4007078E5 /* DCURLRouter.m in Sources */ = {isa = PBXBuildFile; fileRef = 155080961F21F4D4007078E5 /* DCURLRouter.m */; }; 15 | 1550809C1F21F4D4007078E5 /* DCURLRouter.plist in Resources */ = {isa = PBXBuildFile; fileRef = 155080971F21F4D4007078E5 /* DCURLRouter.plist */; }; 16 | 1550809D1F21F4D4007078E5 /* UIViewController+DCURLRouter.m in Sources */ = {isa = PBXBuildFile; fileRef = 155080991F21F4D4007078E5 /* UIViewController+DCURLRouter.m */; }; 17 | 15B071681D64414C00D9D571 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 15B071671D64414B00D9D571 /* main.m */; }; 18 | 15B0716B1D64414C00D9D571 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 15B0716A1D64414C00D9D571 /* AppDelegate.m */; }; 19 | 15B071711D64414C00D9D571 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 15B0716F1D64414C00D9D571 /* Main.storyboard */; }; 20 | 15B071731D64414C00D9D571 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 15B071721D64414C00D9D571 /* Assets.xcassets */; }; 21 | 15B071761D64414C00D9D571 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 15B071741D64414C00D9D571 /* LaunchScreen.storyboard */; }; 22 | 15B0718F1D6468AF00D9D571 /* OneViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15B0718E1D6468AF00D9D571 /* OneViewController.m */; }; 23 | 15B071921D6468C300D9D571 /* TwoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15B071911D6468C300D9D571 /* TwoViewController.m */; }; 24 | 15B071951D646CAB00D9D571 /* ThreeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15B071941D646CAB00D9D571 /* ThreeViewController.m */; }; 25 | 15B071981D646CC000D9D571 /* FourViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15B071971D646CC000D9D571 /* FourViewController.m */; }; 26 | 15B0719B1D646CE600D9D571 /* FiveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15B0719A1D646CE600D9D571 /* FiveViewController.m */; }; 27 | 15E021971D654A2E00B7A6BD /* WebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 15E021961D654A2E00B7A6BD /* WebViewController.m */; }; 28 | /* End PBXBuildFile section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 15143CA91D66AB24006BD05D /* OneChildView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OneChildView.h; sourceTree = ""; }; 32 | 15143CAA1D66AB24006BD05D /* OneChildView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OneChildView.m; sourceTree = ""; }; 33 | 1526ABED1D6B316D0083C658 /* XibViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XibViewController.h; sourceTree = ""; }; 34 | 1526ABEE1D6B316D0083C658 /* XibViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XibViewController.m; sourceTree = ""; }; 35 | 1526ABEF1D6B316D0083C658 /* XibViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = XibViewController.xib; sourceTree = ""; }; 36 | 155080921F21F4D4007078E5 /* DCSingleton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DCSingleton.h; sourceTree = ""; }; 37 | 155080931F21F4D4007078E5 /* DCURLNavgation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DCURLNavgation.h; sourceTree = ""; }; 38 | 155080941F21F4D4007078E5 /* DCURLNavgation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DCURLNavgation.m; sourceTree = ""; }; 39 | 155080951F21F4D4007078E5 /* DCURLRouter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DCURLRouter.h; sourceTree = ""; }; 40 | 155080961F21F4D4007078E5 /* DCURLRouter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DCURLRouter.m; sourceTree = ""; }; 41 | 155080971F21F4D4007078E5 /* DCURLRouter.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = DCURLRouter.plist; sourceTree = ""; }; 42 | 155080981F21F4D4007078E5 /* UIViewController+DCURLRouter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+DCURLRouter.h"; sourceTree = ""; }; 43 | 155080991F21F4D4007078E5 /* UIViewController+DCURLRouter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+DCURLRouter.m"; sourceTree = ""; }; 44 | 15B071631D64414B00D9D571 /* DCURLRouterDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DCURLRouterDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 15B071671D64414B00D9D571 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 46 | 15B071691D64414C00D9D571 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 47 | 15B0716A1D64414C00D9D571 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 48 | 15B071701D64414C00D9D571 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 49 | 15B071721D64414C00D9D571 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 50 | 15B071751D64414C00D9D571 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 51 | 15B071771D64414C00D9D571 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 15B0718D1D6468AF00D9D571 /* OneViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OneViewController.h; sourceTree = ""; }; 53 | 15B0718E1D6468AF00D9D571 /* OneViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OneViewController.m; sourceTree = ""; }; 54 | 15B071901D6468C300D9D571 /* TwoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TwoViewController.h; sourceTree = ""; }; 55 | 15B071911D6468C300D9D571 /* TwoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TwoViewController.m; sourceTree = ""; }; 56 | 15B071931D646CAB00D9D571 /* ThreeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreeViewController.h; sourceTree = ""; }; 57 | 15B071941D646CAB00D9D571 /* ThreeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreeViewController.m; sourceTree = ""; }; 58 | 15B071961D646CC000D9D571 /* FourViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FourViewController.h; sourceTree = ""; }; 59 | 15B071971D646CC000D9D571 /* FourViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FourViewController.m; sourceTree = ""; }; 60 | 15B071991D646CE600D9D571 /* FiveViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FiveViewController.h; sourceTree = ""; }; 61 | 15B0719A1D646CE600D9D571 /* FiveViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FiveViewController.m; sourceTree = ""; }; 62 | 15E021951D654A2E00B7A6BD /* WebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewController.h; sourceTree = ""; }; 63 | 15E021961D654A2E00B7A6BD /* WebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewController.m; sourceTree = ""; }; 64 | /* End PBXFileReference section */ 65 | 66 | /* Begin PBXFrameworksBuildPhase section */ 67 | 15B071601D64414B00D9D571 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | /* End PBXFrameworksBuildPhase section */ 75 | 76 | /* Begin PBXGroup section */ 77 | 155080911F21F4D4007078E5 /* DCURLRouter */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 155080921F21F4D4007078E5 /* DCSingleton.h */, 81 | 155080931F21F4D4007078E5 /* DCURLNavgation.h */, 82 | 155080941F21F4D4007078E5 /* DCURLNavgation.m */, 83 | 155080951F21F4D4007078E5 /* DCURLRouter.h */, 84 | 155080961F21F4D4007078E5 /* DCURLRouter.m */, 85 | 155080971F21F4D4007078E5 /* DCURLRouter.plist */, 86 | 155080981F21F4D4007078E5 /* UIViewController+DCURLRouter.h */, 87 | 155080991F21F4D4007078E5 /* UIViewController+DCURLRouter.m */, 88 | ); 89 | name = DCURLRouter; 90 | path = ../DCURLRouter; 91 | sourceTree = ""; 92 | }; 93 | 15B0715A1D64414B00D9D571 = { 94 | isa = PBXGroup; 95 | children = ( 96 | 155080911F21F4D4007078E5 /* DCURLRouter */, 97 | 15B071651D64414B00D9D571 /* DCURLRouterDemo */, 98 | 15B071641D64414B00D9D571 /* Products */, 99 | ); 100 | sourceTree = ""; 101 | }; 102 | 15B071641D64414B00D9D571 /* Products */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 15B071631D64414B00D9D571 /* DCURLRouterDemo.app */, 106 | ); 107 | name = Products; 108 | sourceTree = ""; 109 | }; 110 | 15B071651D64414B00D9D571 /* DCURLRouterDemo */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 15B0716F1D64414C00D9D571 /* Main.storyboard */, 114 | 15B071691D64414C00D9D571 /* AppDelegate.h */, 115 | 15B0716A1D64414C00D9D571 /* AppDelegate.m */, 116 | 15B0718D1D6468AF00D9D571 /* OneViewController.h */, 117 | 15B0718E1D6468AF00D9D571 /* OneViewController.m */, 118 | 15B071901D6468C300D9D571 /* TwoViewController.h */, 119 | 15B071911D6468C300D9D571 /* TwoViewController.m */, 120 | 15B071931D646CAB00D9D571 /* ThreeViewController.h */, 121 | 15B071941D646CAB00D9D571 /* ThreeViewController.m */, 122 | 15B071961D646CC000D9D571 /* FourViewController.h */, 123 | 15B071971D646CC000D9D571 /* FourViewController.m */, 124 | 15B071991D646CE600D9D571 /* FiveViewController.h */, 125 | 15B0719A1D646CE600D9D571 /* FiveViewController.m */, 126 | 15E021951D654A2E00B7A6BD /* WebViewController.h */, 127 | 15E021961D654A2E00B7A6BD /* WebViewController.m */, 128 | 1526ABED1D6B316D0083C658 /* XibViewController.h */, 129 | 1526ABEE1D6B316D0083C658 /* XibViewController.m */, 130 | 1526ABEF1D6B316D0083C658 /* XibViewController.xib */, 131 | 15143CA91D66AB24006BD05D /* OneChildView.h */, 132 | 15143CAA1D66AB24006BD05D /* OneChildView.m */, 133 | 15B071721D64414C00D9D571 /* Assets.xcassets */, 134 | 15B071741D64414C00D9D571 /* LaunchScreen.storyboard */, 135 | 15B071771D64414C00D9D571 /* Info.plist */, 136 | 15B071661D64414B00D9D571 /* Supporting Files */, 137 | ); 138 | path = DCURLRouterDemo; 139 | sourceTree = ""; 140 | }; 141 | 15B071661D64414B00D9D571 /* Supporting Files */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | 15B071671D64414B00D9D571 /* main.m */, 145 | ); 146 | name = "Supporting Files"; 147 | sourceTree = ""; 148 | }; 149 | /* End PBXGroup section */ 150 | 151 | /* Begin PBXNativeTarget section */ 152 | 15B071621D64414B00D9D571 /* DCURLRouterDemo */ = { 153 | isa = PBXNativeTarget; 154 | buildConfigurationList = 15B0717A1D64414C00D9D571 /* Build configuration list for PBXNativeTarget "DCURLRouterDemo" */; 155 | buildPhases = ( 156 | 15B0715F1D64414B00D9D571 /* Sources */, 157 | 15B071601D64414B00D9D571 /* Frameworks */, 158 | 15B071611D64414B00D9D571 /* Resources */, 159 | ); 160 | buildRules = ( 161 | ); 162 | dependencies = ( 163 | ); 164 | name = DCURLRouterDemo; 165 | productName = DCURLRouterDemo; 166 | productReference = 15B071631D64414B00D9D571 /* DCURLRouterDemo.app */; 167 | productType = "com.apple.product-type.application"; 168 | }; 169 | /* End PBXNativeTarget section */ 170 | 171 | /* Begin PBXProject section */ 172 | 15B0715B1D64414B00D9D571 /* Project object */ = { 173 | isa = PBXProject; 174 | attributes = { 175 | LastUpgradeCheck = 0800; 176 | ORGANIZATIONNAME = DarielChen; 177 | TargetAttributes = { 178 | 15B071621D64414B00D9D571 = { 179 | CreatedOnToolsVersion = 7.3.1; 180 | }; 181 | }; 182 | }; 183 | buildConfigurationList = 15B0715E1D64414B00D9D571 /* Build configuration list for PBXProject "DCURLRouterDemo" */; 184 | compatibilityVersion = "Xcode 3.2"; 185 | developmentRegion = English; 186 | hasScannedForEncodings = 0; 187 | knownRegions = ( 188 | en, 189 | Base, 190 | ); 191 | mainGroup = 15B0715A1D64414B00D9D571; 192 | productRefGroup = 15B071641D64414B00D9D571 /* Products */; 193 | projectDirPath = ""; 194 | projectRoot = ""; 195 | targets = ( 196 | 15B071621D64414B00D9D571 /* DCURLRouterDemo */, 197 | ); 198 | }; 199 | /* End PBXProject section */ 200 | 201 | /* Begin PBXResourcesBuildPhase section */ 202 | 15B071611D64414B00D9D571 /* Resources */ = { 203 | isa = PBXResourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | 1526ABF11D6B316D0083C658 /* XibViewController.xib in Resources */, 207 | 1550809C1F21F4D4007078E5 /* DCURLRouter.plist in Resources */, 208 | 15B071761D64414C00D9D571 /* LaunchScreen.storyboard in Resources */, 209 | 15B071731D64414C00D9D571 /* Assets.xcassets in Resources */, 210 | 15B071711D64414C00D9D571 /* Main.storyboard in Resources */, 211 | ); 212 | runOnlyForDeploymentPostprocessing = 0; 213 | }; 214 | /* End PBXResourcesBuildPhase section */ 215 | 216 | /* Begin PBXSourcesBuildPhase section */ 217 | 15B0715F1D64414B00D9D571 /* Sources */ = { 218 | isa = PBXSourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | 15B071921D6468C300D9D571 /* TwoViewController.m in Sources */, 222 | 1526ABF01D6B316D0083C658 /* XibViewController.m in Sources */, 223 | 1550809D1F21F4D4007078E5 /* UIViewController+DCURLRouter.m in Sources */, 224 | 15E021971D654A2E00B7A6BD /* WebViewController.m in Sources */, 225 | 1550809B1F21F4D4007078E5 /* DCURLRouter.m in Sources */, 226 | 1550809A1F21F4D4007078E5 /* DCURLNavgation.m in Sources */, 227 | 15B071981D646CC000D9D571 /* FourViewController.m in Sources */, 228 | 15B0719B1D646CE600D9D571 /* FiveViewController.m in Sources */, 229 | 15143CAB1D66AB24006BD05D /* OneChildView.m in Sources */, 230 | 15B0716B1D64414C00D9D571 /* AppDelegate.m in Sources */, 231 | 15B0718F1D6468AF00D9D571 /* OneViewController.m in Sources */, 232 | 15B071681D64414C00D9D571 /* main.m in Sources */, 233 | 15B071951D646CAB00D9D571 /* ThreeViewController.m in Sources */, 234 | ); 235 | runOnlyForDeploymentPostprocessing = 0; 236 | }; 237 | /* End PBXSourcesBuildPhase section */ 238 | 239 | /* Begin PBXVariantGroup section */ 240 | 15B0716F1D64414C00D9D571 /* Main.storyboard */ = { 241 | isa = PBXVariantGroup; 242 | children = ( 243 | 15B071701D64414C00D9D571 /* Base */, 244 | ); 245 | name = Main.storyboard; 246 | sourceTree = ""; 247 | }; 248 | 15B071741D64414C00D9D571 /* LaunchScreen.storyboard */ = { 249 | isa = PBXVariantGroup; 250 | children = ( 251 | 15B071751D64414C00D9D571 /* Base */, 252 | ); 253 | name = LaunchScreen.storyboard; 254 | sourceTree = ""; 255 | }; 256 | /* End PBXVariantGroup section */ 257 | 258 | /* Begin XCBuildConfiguration section */ 259 | 15B071781D64414C00D9D571 /* Debug */ = { 260 | isa = XCBuildConfiguration; 261 | buildSettings = { 262 | ALWAYS_SEARCH_USER_PATHS = NO; 263 | CLANG_ANALYZER_NONNULL = YES; 264 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 265 | CLANG_CXX_LIBRARY = "libc++"; 266 | CLANG_ENABLE_MODULES = YES; 267 | CLANG_ENABLE_OBJC_ARC = YES; 268 | CLANG_WARN_BOOL_CONVERSION = YES; 269 | CLANG_WARN_CONSTANT_CONVERSION = YES; 270 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 271 | CLANG_WARN_EMPTY_BODY = YES; 272 | CLANG_WARN_ENUM_CONVERSION = YES; 273 | CLANG_WARN_INFINITE_RECURSION = YES; 274 | CLANG_WARN_INT_CONVERSION = YES; 275 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 276 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 277 | CLANG_WARN_UNREACHABLE_CODE = YES; 278 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 279 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 280 | COPY_PHASE_STRIP = NO; 281 | DEBUG_INFORMATION_FORMAT = dwarf; 282 | ENABLE_STRICT_OBJC_MSGSEND = YES; 283 | ENABLE_TESTABILITY = YES; 284 | GCC_C_LANGUAGE_STANDARD = gnu99; 285 | GCC_DYNAMIC_NO_PIC = NO; 286 | GCC_NO_COMMON_BLOCKS = YES; 287 | GCC_OPTIMIZATION_LEVEL = 0; 288 | GCC_PREPROCESSOR_DEFINITIONS = ( 289 | "DEBUG=1", 290 | "$(inherited)", 291 | ); 292 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 293 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 294 | GCC_WARN_UNDECLARED_SELECTOR = YES; 295 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 296 | GCC_WARN_UNUSED_FUNCTION = YES; 297 | GCC_WARN_UNUSED_VARIABLE = YES; 298 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 299 | MTL_ENABLE_DEBUG_INFO = YES; 300 | ONLY_ACTIVE_ARCH = YES; 301 | SDKROOT = iphoneos; 302 | }; 303 | name = Debug; 304 | }; 305 | 15B071791D64414C00D9D571 /* Release */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | ALWAYS_SEARCH_USER_PATHS = NO; 309 | CLANG_ANALYZER_NONNULL = YES; 310 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 311 | CLANG_CXX_LIBRARY = "libc++"; 312 | CLANG_ENABLE_MODULES = YES; 313 | CLANG_ENABLE_OBJC_ARC = YES; 314 | CLANG_WARN_BOOL_CONVERSION = YES; 315 | CLANG_WARN_CONSTANT_CONVERSION = YES; 316 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 317 | CLANG_WARN_EMPTY_BODY = YES; 318 | CLANG_WARN_ENUM_CONVERSION = YES; 319 | CLANG_WARN_INFINITE_RECURSION = YES; 320 | CLANG_WARN_INT_CONVERSION = YES; 321 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 322 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 323 | CLANG_WARN_UNREACHABLE_CODE = YES; 324 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 325 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 326 | COPY_PHASE_STRIP = NO; 327 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 328 | ENABLE_NS_ASSERTIONS = NO; 329 | ENABLE_STRICT_OBJC_MSGSEND = YES; 330 | GCC_C_LANGUAGE_STANDARD = gnu99; 331 | GCC_NO_COMMON_BLOCKS = YES; 332 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 333 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 334 | GCC_WARN_UNDECLARED_SELECTOR = YES; 335 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 336 | GCC_WARN_UNUSED_FUNCTION = YES; 337 | GCC_WARN_UNUSED_VARIABLE = YES; 338 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 339 | MTL_ENABLE_DEBUG_INFO = NO; 340 | SDKROOT = iphoneos; 341 | VALIDATE_PRODUCT = YES; 342 | }; 343 | name = Release; 344 | }; 345 | 15B0717B1D64414C00D9D571 /* Debug */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 349 | INFOPLIST_FILE = DCURLRouterDemo/Info.plist; 350 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 351 | PRODUCT_BUNDLE_IDENTIFIER = io.github.DarielChen.DCURLRouterDemo; 352 | PRODUCT_NAME = "$(TARGET_NAME)"; 353 | }; 354 | name = Debug; 355 | }; 356 | 15B0717C1D64414C00D9D571 /* Release */ = { 357 | isa = XCBuildConfiguration; 358 | buildSettings = { 359 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 360 | INFOPLIST_FILE = DCURLRouterDemo/Info.plist; 361 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 362 | PRODUCT_BUNDLE_IDENTIFIER = io.github.DarielChen.DCURLRouterDemo; 363 | PRODUCT_NAME = "$(TARGET_NAME)"; 364 | }; 365 | name = Release; 366 | }; 367 | /* End XCBuildConfiguration section */ 368 | 369 | /* Begin XCConfigurationList section */ 370 | 15B0715E1D64414B00D9D571 /* Build configuration list for PBXProject "DCURLRouterDemo" */ = { 371 | isa = XCConfigurationList; 372 | buildConfigurations = ( 373 | 15B071781D64414C00D9D571 /* Debug */, 374 | 15B071791D64414C00D9D571 /* Release */, 375 | ); 376 | defaultConfigurationIsVisible = 0; 377 | defaultConfigurationName = Release; 378 | }; 379 | 15B0717A1D64414C00D9D571 /* Build configuration list for PBXNativeTarget "DCURLRouterDemo" */ = { 380 | isa = XCConfigurationList; 381 | buildConfigurations = ( 382 | 15B0717B1D64414C00D9D571 /* Debug */, 383 | 15B0717C1D64414C00D9D571 /* Release */, 384 | ); 385 | defaultConfigurationIsVisible = 0; 386 | defaultConfigurationName = Release; 387 | }; 388 | /* End XCConfigurationList section */ 389 | }; 390 | rootObject = 15B0715B1D64414B00D9D571 /* Project object */; 391 | } 392 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "DCURLRouter.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | 21 | [DCURLRouter loadConfigDictFromPlist:@"DCURLRouter.plist"]; 22 | 23 | return YES; 24 | } 25 | 26 | - (void)applicationWillResignActive:(UIApplication *)application { 27 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 28 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 29 | } 30 | 31 | - (void)applicationDidEnterBackground:(UIApplication *)application { 32 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 33 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 34 | } 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | - (void)applicationDidBecomeActive:(UIApplication *)application { 41 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 42 | } 43 | 44 | - (void)applicationWillTerminate:(UIApplication *)application { 45 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconNormal.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "ZHEditorSettingIconNormal@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "ZHEditorSettingIconNormal@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconNormal.imageset/ZHEditorSettingIconNormal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DarielChen/DCURLRouter/d64e5a451e6b1dec717e56e9a0eca9a369ce4937/DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconNormal.imageset/ZHEditorSettingIconNormal@2x.png -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconNormal.imageset/ZHEditorSettingIconNormal@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DarielChen/DCURLRouter/d64e5a451e6b1dec717e56e9a0eca9a369ce4937/DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconNormal.imageset/ZHEditorSettingIconNormal@3x.png -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconOpen.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "ZHEditorSettingIconOpen@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "ZHEditorSettingIconOpen@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconOpen.imageset/ZHEditorSettingIconOpen@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DarielChen/DCURLRouter/d64e5a451e6b1dec717e56e9a0eca9a369ce4937/DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconOpen.imageset/ZHEditorSettingIconOpen@2x.png -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconOpen.imageset/ZHEditorSettingIconOpen@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DarielChen/DCURLRouter/d64e5a451e6b1dec717e56e9a0eca9a369ce4937/DCURLRouterDemo/DCURLRouterDemo/Assets.xcassets/ZHEditorSettingIconOpen.imageset/ZHEditorSettingIconOpen@3x.png -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/FiveViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FiveViewController.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FiveViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/FiveViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // FiveViewController.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "FiveViewController.h" 10 | #import "DCURLRouter.h" 11 | 12 | @implementation FiveViewController 13 | 14 | - (void)viewDidLoad { 15 | [super viewDidLoad]; 16 | 17 | self.view.backgroundColor = [UIColor whiteColor]; 18 | 19 | UILabel *title = [[UILabel alloc] init]; 20 | title.text = NSStringFromClass([self class]); 21 | title.font = [UIFont systemFontOfSize:20]; 22 | title.textColor = [UIColor lightGrayColor]; 23 | title.numberOfLines = 0; 24 | [title sizeToFit]; 25 | [self.view addSubview:title]; 26 | title.center = self.view.center; 27 | 28 | 29 | self.navigationItem.title = @"FiveViewController"; 30 | } 31 | 32 | -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 33 | 34 | // [DCURLRouter presentURLString:@"dariel://threeitem" animated:YES]; 35 | 36 | // [DCURLRouter popToRootViewControllerAnimated:YES]; 37 | 38 | // [DCURLRouter popTwiceViewControllerAnimated:YES]; 39 | 40 | // [DCURLRouter popViewControllerWithTimes:3 animated:YES]; 41 | 42 | 43 | // [DCURLRouter popViewControllerAnimated:YES]; 44 | // [DCURLRouter dismissViewControllerWithTimes:5 animated:YES completion:nil]; 45 | 46 | // [DCURLRouter dismissToRootViewControllerAnimated:YES completion:nil]; 47 | 48 | // [DCURLRouter dismissToRootViewControllerAnimated:YES completion:nil]; 49 | 50 | // [DCURLRouter dismissTwiceViewControllerAnimated:YES completion:nil]; 51 | 52 | [DCURLRouter pushURLString:@"http://www.baidu.com" animated:YES]; 53 | 54 | // [DCURLRouter presentURLString:@"http://www.baidu.com" animated:YES]; 55 | 56 | // [DCURLRouter pushURLString:@"https://www.baidu.com" animated:YES]; 57 | 58 | } 59 | 60 | - (void)dealloc { 61 | 62 | NSLog(@"%s", __func__); 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/FourViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FourViewController.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FourViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/FourViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // FourViewController.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "FourViewController.h" 10 | #import "DCURLRouter.h" 11 | 12 | @implementation FourViewController 13 | 14 | - (void)viewDidLoad { 15 | [super viewDidLoad]; 16 | 17 | self.view.backgroundColor = [UIColor whiteColor]; 18 | 19 | self.navigationItem.title = @"FourViewController"; 20 | 21 | 22 | UILabel *title = [[UILabel alloc] init]; 23 | title.text = NSStringFromClass([self class]); 24 | title.font = [UIFont systemFontOfSize:20]; 25 | title.textColor = [UIColor lightGrayColor]; 26 | title.numberOfLines = 0; 27 | [title sizeToFit]; 28 | [self.view addSubview:title]; 29 | title.center = self.view.center; 30 | 31 | } 32 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 33 | 34 | [DCURLRouter pushURLString:@"dariel://fiveitem" animated:YES replace:NO]; 35 | 36 | // [DCURLRouter presentURLString:@"dariel://fiveitem" animated:YES]; 37 | // [DCURLRouter presentURLString:@"dariel://fiveitem" animated:YES completion:nil]; 38 | 39 | } 40 | 41 | - (void)dealloc { 42 | 43 | NSLog(@"%s", __func__); 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | NSAppTransportSecurity 40 | 41 | NSAllowsArbitraryLoads 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/OneChildView.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneChildView.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/19. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneChildView : UIView 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/OneChildView.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneChildView.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/19. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "OneChildView.h" 10 | #import "DCURLRouter.h" 11 | 12 | @implementation OneChildView 13 | 14 | - (instancetype)initWithFrame:(CGRect)frame 15 | { 16 | if (self = [super initWithFrame:frame]) { 17 | 18 | self.backgroundColor = [UIColor cyanColor]; 19 | 20 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addClick:)]; 21 | [self addGestureRecognizer:tap]; 22 | } 23 | return self; 24 | } 25 | 26 | - (void)addClick:(UITapGestureRecognizer *)gesture 27 | { 28 | NSString *urlStr = @"dariel://twoitem?name=dariel&userid=213213"; 29 | [DCURLRouter pushURLString:urlStr animated:YES]; 30 | 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/OneViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OneViewController.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OneViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/OneViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OneViewController.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "OneViewController.h" 10 | #import "DCURLRouter.h" 11 | #import "TwoViewController.h" 12 | #import "OneChildView.h" 13 | 14 | @implementation OneViewController 15 | 16 | - (void)viewDidLoad { 17 | [super viewDidLoad]; 18 | 19 | self.view.backgroundColor = [UIColor whiteColor]; 20 | self.navigationItem.title = @"OneViewController"; 21 | 22 | UILabel *title = [[UILabel alloc] init]; 23 | title.text = NSStringFromClass([self class]); 24 | title.font = [UIFont systemFontOfSize:20]; 25 | title.textColor = [UIColor lightGrayColor]; 26 | title.numberOfLines = 0; 27 | [title sizeToFit]; 28 | [self.view addSubview:title]; 29 | title.center = self.view.center; 30 | 31 | 32 | OneChildView *oneView = [[OneChildView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; 33 | [self.view addSubview:oneView]; 34 | 35 | } 36 | 37 | 38 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 39 | 40 | 41 | // [DCURLRouter presentURLString:@"dariel://twoitem?name=nsdn&age= 你好" animated:YES completion:nil]; 42 | 43 | [DCURLRouter pushURLString:@"dariel://twoitem?name=nsdn&age= 18" animated:YES]; 44 | 45 | NSLog(@"%@", [DCURLRouter sharedDCURLRouter].currentViewController); 46 | 47 | UIViewController *twoVc = [DCURLRouter sharedDCURLRouter].currentViewController; 48 | twoVc.valueBlock = ^(id value) { 49 | NSLog(@"%@", value); 50 | }; 51 | 52 | // [DCURLRouter dismissViewControllerWithTimes:1 animated:YES completion:nil]; 53 | 54 | } 55 | 56 | 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/ThreeViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ThreeViewController.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ThreeViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/ThreeViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ThreeViewController.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "ThreeViewController.h" 10 | #import "DCURLRouter.h" 11 | 12 | @implementation ThreeViewController 13 | 14 | - (void)viewDidLoad { 15 | [super viewDidLoad]; 16 | 17 | self.view.backgroundColor = [UIColor whiteColor]; 18 | 19 | self.navigationItem.title = @"ThreeViewController"; 20 | 21 | // NSLog(@"originUrl:%@",self.originUrl); 22 | // NSLog(@"path:%@", self.path); 23 | // NSLog(@"params:%@", self.params); 24 | 25 | UILabel *title = [[UILabel alloc] init]; 26 | title.text = NSStringFromClass([self class]); 27 | title.font = [UIFont systemFontOfSize:20]; 28 | title.textColor = [UIColor lightGrayColor]; 29 | title.numberOfLines = 0; 30 | [title sizeToFit]; 31 | [self.view addSubview:title]; 32 | title.center = self.view.center; 33 | } 34 | 35 | 36 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 37 | 38 | [DCURLRouter pushURLString:@"dariel://fouritem" animated:YES replace:NO]; 39 | 40 | // [DCURLRouter presentURLString:@"dariel://fouritem" animated:YES completion:nil]; 41 | 42 | } 43 | 44 | 45 | - (void)dealloc { 46 | 47 | NSLog(@"%s", __func__); 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/TwoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TwoViewController.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TwoViewController : UIViewController 12 | 13 | @property (nonatomic, copy) NSString *name; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/TwoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TwoViewController.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "TwoViewController.h" 10 | #import "DCURLRouter.h" 11 | #import "UIViewController+DCURLRouter.h" 12 | #import "ThreeViewController.h" 13 | 14 | @interface TwoViewController() 15 | 16 | @end 17 | 18 | @implementation TwoViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | 23 | self.view.backgroundColor = [UIColor whiteColor]; 24 | self.navigationItem.title = @"TwoViewController"; 25 | 26 | UILabel *title = [[UILabel alloc] init]; 27 | title.text = NSStringFromClass([self class]); 28 | title.font = [UIFont systemFontOfSize:20]; 29 | title.textColor = [UIColor lightGrayColor]; 30 | title.numberOfLines = 0; 31 | [title sizeToFit]; 32 | [self.view addSubview:title]; 33 | title.center = self.view.center; 34 | 35 | NSLog(@"接收的参数%@", self.params); 36 | NSLog(@"age:%@", self.params[@"age"]); 37 | 38 | NSLog(@"拿到URL:%@", self.originUrl); 39 | NSLog(@"URL路径:%@", self.path); 40 | 41 | // NSLog(@"%@", self.name); 42 | 43 | 44 | } 45 | 46 | 47 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 48 | 49 | // [DCURLRouter presentURLString:@"dariel://threeitem" animated:YES completion:nil]; 50 | 51 | self.valueBlock(@"any Type"); 52 | 53 | } 54 | 55 | 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/WebViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewController.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/18. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WebViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/WebViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewController.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/18. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "WebViewController.h" 10 | #import "DCURLRouter.h" 11 | 12 | @interface WebViewController () 13 | 14 | @property (nonatomic, strong) UIWebView *webView; 15 | 16 | 17 | @end 18 | 19 | @implementation WebViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | 24 | self.view.backgroundColor = [self randomColors]; 25 | 26 | self.navigationController.title = NSStringFromClass([self class]); 27 | 28 | NSLog(@"originUrl:%@",self.originUrl); 29 | NSLog(@"path:%@", self.path); 30 | NSLog(@"params:%@", self.params); 31 | 32 | UIWebView *webView = [[UIWebView alloc] init]; 33 | self.webView = webView; 34 | webView.frame = self.view.bounds; 35 | [self.view addSubview:webView]; 36 | 37 | NSURL *url = [NSURL URLWithString:self.params[@"urlStr"]]; 38 | NSURLRequest *request = [NSURLRequest requestWithURL:url]; 39 | [self.webView loadRequest:request]; 40 | } 41 | 42 | 43 | - (UIColor *)randomColors 44 | { 45 | CGFloat r = arc4random_uniform(256)/255.0; 46 | CGFloat g = arc4random_uniform(256)/255.0; 47 | CGFloat b = arc4random_uniform(256)/255.0; 48 | 49 | return [UIColor colorWithRed:r green:g blue:b alpha:1]; 50 | 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/XibViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XibViewController.h 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/22. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XibViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/XibViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // XibViewController.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/22. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import "XibViewController.h" 10 | 11 | @interface XibViewController () 12 | 13 | @end 14 | 15 | @implementation XibViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | 20 | 21 | UILabel *title = [[UILabel alloc] init]; 22 | title.text = NSStringFromClass([self class]); 23 | title.font = [UIFont systemFontOfSize:20]; 24 | title.textColor = [UIColor lightGrayColor]; 25 | title.numberOfLines = 0; 26 | [title sizeToFit]; 27 | [self.view addSubview:title]; 28 | title.center = self.view.center; 29 | 30 | self.navigationItem.title = @"XibViewController"; 31 | } 32 | 33 | - (void)didReceiveMemoryWarning { 34 | [super didReceiveMemoryWarning]; 35 | // Dispose of any resources that can be recreated. 36 | } 37 | 38 | 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/XibViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DCURLRouterDemo/DCURLRouterDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DCURLRouterDemo 4 | // 5 | // Created by Dariel on 16/8/17. 6 | // Copyright © 2016年 DarielChen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Dariel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DCURLRouter 2 | 3 | ## 介绍 4 | 通过自定义URL实现控制器之间的跳转. 5 | 6 | 主要功能: 7 | * 支持URL后面拼接参数; 8 | * 支持参数作为字典传入; 9 | * 支持在push的时候进行导航控制器的替换; 10 | * 支持在modal的时候添加导航控制器; 11 | * 支持一次pop和dismiss多个控制器; 12 | * 支持使用Xib加载控制器; 13 | * 自带block回调; 14 | * 兼容swift. 15 | 16 | --- 17 | ## 使用方法: 18 | 19 | ### 1. 把`DCURLRouter`这个文件夹拖到项目中. 20 | 21 | ### 2. 使用`cocoapods`: 22 | 23 | pod 'DCURLRouter', '~> 0.81' 24 | 25 | 注意: 需要自己在项目中新建一个DCURLRouter.plist文件. 26 | 27 | --- 28 | ## 1.配置 29 | 1. 创建DCURLRouter.一个plist文件,文件夹中有,只要修改下就行了,大概的对应关系如下图所示 30 | ![](http://upload-images.jianshu.io/upload_images/924285-3a4ba764f9860049.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 31 | 2. 加载DCURLRouter.plist文件数据 32 | 33 | ```Objective-C 34 | [DCURLRouter loadConfigDictFromPlist:@"DCURLRouter.plist"]; 35 | ``` 36 | 37 | ## 2. push和modal的使用 38 | 所有的push和modal方法都可以通过DCURLRouter这个类方法来调用.这样在push和modal的时候就不需要拿到导航控制器或控制器再跳转了.也就是说,以后push和modal控制器跳转就不一定要在控制器中进行了. 39 | 40 | 1.push控制器 41 | 42 | ```Objective-C 43 | // 不需要拼接参数直接跳转 44 | [DCURLRouter pushURLString:@"dariel://twoitem" animated:YES]; 45 | 46 | // 直接把参数拼接在自定义url末尾 47 | NSString *urlStr = @"dariel://twoitem?name=dariel&userid=213213"; 48 | [DCURLRouter pushURLString:urlStr animated:YES]; 49 | // 可以将参数放入一个字典 50 | NSDictionary *dict = @{@"userName":@"Hello", @"userid":@"32342"}; 51 | [DCURLRouter pushURLString:@"dariel://twoitem" query:dict animated:YES]; 52 | 53 | // 如果当前控制器和要push的控制器是同一个,可以将replace设置为Yes,进行替换. 54 | [DCURLRouter pushURLString:@"dariel://oneitem" query:dict animated:YES replace:YES]; 55 | 56 | // 重写了系统的push方法,直接通过控制器跳转 57 | TwoViewController *two = [[TwoViewController alloc] init]; 58 | [DCURLRouter pushViewController:two animated:YES]; 59 | ``` 60 | 2.modal控制器 61 | 用法和push差不多,只是这里添加了一个给modal出来的控制器加一个导航控制器的方法. 62 | 63 | 64 | ```Objective-C 65 | // 不需要拼接参数直接跳转 66 | [DCURLRouter presentURLString:@"dariel://threeitem" animated:YES completion:nil]; 67 | 68 | // 直接把参数拼接在自定义url末尾 69 | NSString *urlStr = @"dariel://threeitem?name=dariel&userid=213213"; 70 | [DCURLRouter presentURLString:urlStr animated:YES completion:nil]; 71 | 72 | // 可以将参数放入一个字典 73 | NSDictionary *dict = @{@"userName":@"Hello", @"userid":@"32342"}; 74 | [DCURLRouter presentURLString:@"dariel://threeitem" query:dict animated:YES completion:nil]; 75 | 76 | // 给modal出来的控制器添加一个导航控制器 77 | [DCURLRouter presentURLString:@"dariel://threeitem" animated:YES withNavigationClass:[UINavigationController class] completion:nil]; 78 | 79 | // 重写了系统的modal方法 80 | ThreeViewController *three = [[ThreeViewController alloc] init]; 81 | [DCURLRouter presentViewController:three animated:YES completion:nil]; 82 | ``` 83 | 84 | ## 3. 后退 pop 和 dismiss 85 | 在实际开发中,好几次的界面的跳转组成了一个业务流程,整个业务流程结束后通常会要求返回最开始的界面,这就要让控制器连续后退好几次,但苹果是没有提供方法的.DCURLRouter给出了具体的实现方案. 86 | 87 | pop: 88 | 89 | ```Objective-C 90 | /** pop掉一层控制器 */ 91 | + (void)popViewControllerAnimated:(BOOL)animated; 92 | /** pop掉两层控制器 */ 93 | + (void)popTwiceViewControllerAnimated:(BOOL)animated; 94 | /** pop掉times层控制器 */ 95 | + (void)popViewControllerWithTimes:(NSUInteger)times animated:(BOOL)animated; 96 | /** pop到根层控制器 */ 97 | + (void)popToRootViewControllerAnimated:(BOOL)animated; 98 | ``` 99 | dismiss: 100 | 101 | ```Objective-C 102 | /** dismiss掉1层控制器 */ 103 | + (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 104 | /** dismiss掉2层控制器 */ 105 | + (void)dismissTwiceViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 106 | /** dismiss掉times层控制器 */ 107 | + (void)dismissViewControllerWithTimes:(NSUInteger)times animated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 108 | /** dismiss到根层控制器 */ 109 | + (void)dismissToRootViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion; 110 | ``` 111 | ## 4.参数的接收,以及其它方法 112 | 在3中如果在自定义了URL后面拼接了参数,或者用字典传递了参数,那么在目的控制器怎么接收呢?其实参数的接收很简单.只要导入这个分类`#import "UIViewController+DCURLRouter.h"`就行了,然后就能拿到这三个参数. 113 | 114 | ```Objective-C 115 | NSLog(@"接收的参数%@", self.params); 116 | NSLog(@"拿到URL:%@", self.originUrl); 117 | NSLog(@"URL路径:%@", self.path); 118 | ``` 119 | 但有时我们我需要把值传递给发送push或者modal方的控制器,也就是逆传,也很简单,可以用代理.有方法可以拿到当前的控制器,以及导航控制器 120 | 121 | 或者用控制器分类自带的valueBlock属性回调 122 | 123 | ```Objective-C 124 | // 拿到当前控制器 125 | UIViewController *currentController = [DCURLRouter sharedDCURLRouter].currentViewController; 126 | // 拿到当前控制器的导航控制器 127 | UINavigationController *currentNavgationController = [DCURLRouter sharedDCURLRouter].currentNavigationViewController; 128 | 129 | ``` 130 | ## 5.具体的实现原理 131 | [简书](http://www.jianshu.com/p/36a43202b0cd) 132 | --------------------------------------------------------------------------------