To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 8.0 or later
JOURLRouter is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "JOURLRouter"
-
create a instance which implement the protocol JOURLRouterDelegate
-
config JOURLRouter
@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
-
implement the protocol JOURLRouterProtocol
@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); }
-
Then you can use
[JOURLRouter openUrl:@"https://www.kujiale.com/demo/first/firstvc"]
to push JOFirstViewController without import it
JOURLRouter is available under the MIT license. See the LICENSE file for more info.