Latest 1.0.0
Homepage https://github.com/ABCReading/ATRouter
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

ATRouter is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'ATRouter'
    1. pod 安装后需要在项目宿主工程中创建一个全局的header 协议文件,用于声明所有需要协议路由router的VC协议,示例如下:
    #ifndef ATSupportedControllers_h
    #define ATSupportedControllers_h
    // TwoVC
    @protocol ATTwoViewController 
    @end
    #endif
    
    1. 在每一个频道(模块)Module下,创建一个bind module class 用来绑定所有已被ATSupportedControllers.h声明过的VC,示例如下:
    /// .h 文件
    #import 
    @interface ATBindClassModule : JSObjectionModule
    
    @end
    
    /// .m文件
    #import "ATBindClassModule.h"
    #import "ATSupportedControllers.h"
    #import "ATTwoViewController.h"
    
    @implementation ATBindClassModule
    + (void)load {
      JSObjectionInjector *injector = [JSObjection defaultInjector];
      injector = injector ? : [JSObjection createInjector];
      injector = [injector withModule:[[self alloc] init]];
      [JSObjection setDefaultInjector:injector];
    }
    
    - (void)configure {
      // twoVC
      [self bindMetaClass:ATTwoViewController.class toProtocol:@protocol(ATTwoViewController)];
    }
    
    @end    
    
    1. 在每一个频道(模块)Module下,创建一个ATRouter分类,用于注册VC route,示例如下:

      /// .h文件
      #import 
      
      NS_ASSUME_NONNULL_BEGIN
      
      @interface ATRouter (Test)
      
      @end
      
      /// .m文件
      #import "ATRouter+Test.h"
      #import "ATSupportedControllers.h"
      #import 
      #import 
      #import 
      static NSString *routerStr = @"/TwoVC/pass";
      @implementation ATRouter (Test)
      + (void)load {
       // webVC
       [ATRouter addRoute:routerStr handler:^BOOL(NSDictionary *parameters) {
           id destination = [[JSObjection defaultInjector] getObject:@protocol(ATTwoViewController)];
      
           UIViewController *c = [destination createInstanceWithParameters:parameters];
      
           if (!c) {
               return NO;
           }
      
           [self navigationWithController:c parameters:parameters];
           return YES;
       }];
      
      }
      @end
      
    1. 在需要路由的VC里遵循协议,并且实现createInstanceWithParameters工厂方法,示例如下:
    #import "ATTwoViewController.h"
    #import 
    @interface ATTwoViewController () 
    
    @end
    
    @implementation ATTwoViewController
    
    - (void)viewDidLoad {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
      self.title = NSStringFromClass(self.class);
      self.view.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
    }
    
    + (UIViewController *)createInstanceWithParameters:(NSDictionary *)parameters {
      NSLog(@"%@", parameters);
      return [self new];
    }
    @end
    
    1. 在根nav或tab里遵循协议,并且实现createInstanceWithParameters工厂方法,示例如下:
    #import "ATViewController.h"
    #import 
    @interface ATViewController () 
    
    @end
    
    @implementation ATViewController
    // MARK: - 
    - (BOOL)routeURL:URL withParameters:(NSDictionary *)parameters {
      return NO;
    }
    
    - (UINavigationController *)activeNavigationController {
      return (UINavigationController *)self.navigationController;
    }
    
    @end
    

Author

ABCReading, [email protected]

License

ATRouter is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "ATRouter",
    "version": "1.0.0",
    "summary": "ABCReading common Router",
    "description": "ABCReading common view controller Router.",
    "homepage": "https://github.com/ABCReading/ATRouter",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ABCReading": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ABCReading/ATRouter.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "ATRouter/Classes/**/*"
}

Pin It on Pinterest

Share This