Skip to content

Latest commit

 

History

History
74 lines (63 loc) · 2.55 KB

README.md

File metadata and controls

74 lines (63 loc) · 2.55 KB

JOURLRouter

CI Status Version License Platform

Example

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

Requirements

iOS 8.0 or later

Installation

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

pod "JOURLRouter"

Usage

  1. create a instance which implement the protocol JOURLRouterDelegate

  2. config JOURLRouter

    Example:

    @import JOURLRouter;
    @interface JOAppDelegate () <JOURLRouterDelegate>
    @end
    @implementation JOAppDelegate
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [JOURLRouter configWithDelegate:self];
        return YES;
    }
    - (UINavigationController * _Nullable)navigationControllerForPushVC:(UIViewController * _Nullable)vc url:(NSString * _Nullable)urlStr {
        UIViewController *rootVC = self.window.rootViewController;
        if ([rootVC isKindOfClass:[UINavigationController  class]]) {
            return (UINavigationController *)rootVC;
        }
        return nil;
    }
    - (NSArray<NSString *> * _Nonnull)hostsForURLRouter {
        return @[@"www.kujiale.com"];
    }
    @end
  3. implement the protocol JOURLRouterProtocol

    Example:

    @interface JOFirstViewController () <JOURLRouterProtocol>
    @end
    + (NSArray<NSString *> *)jo_viewControllerURLRegexPathArray {
        return @[@"/demo/first/.+"];
    }
    + (void)jo_matchingUrl:(NSString *)urlString matchingCompeletionHandler:(JOMatchingCompeletionHandler)compeletionHandler {
        NSArray *path = pathArrayFromURLString(urlString);
        NSString *vcID = [path lastObject];
        JOFirstViewController *vc = [[JOFirstViewController alloc] init];
        vc.vcID = vcID;
        compeletionHandler(vc);
    }
  4. Then you can use [JOURLRouter openUrl:@"https://www.kujiale.com/demo/first/firstvc"]to push JOFirstViewController without import it

Author

bobo@qunhemail.com

License

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