CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

PBMediator 0.2.0

PBMediator 0.2.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Sep 2017

Maintained by hujiaju.



  • By
  • nanhujiaju

NHURLRouterPro

iOS application各个业务组件的相互调用、引用的解耦问题,使用到了中间人+URL Router的方式

Usage:(processing->Build Setting->Enable Strict Checking of objc_msgSend Calls == False)!!!

	pod 'PBMediator'
使用前安全设置Scheme
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //for safe check to setup scheme
    [PBMediator setupForScheme:@"balabala"];
    
    ...
    return YES;
}
应用远程调用
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    //balabala://NHWebBrowser/initWithUrlParams:?url=http://baidu.com
    NSLog(@"url:%@---opt:%@",url,options);
    if ([url.scheme isEqualToString:@"balabala"]) {
        UIViewController *ctr = [[PBMediator shared] remoteCallWithURL:url];
        [self.rootNaviCtr pushViewController:ctr animated:true];
        return true;
    }
    return false;
}
应用内部调用(两种方式:初始化字典传值+分类实现)

1-初始化字典传值方式

- (void)callNativeWebBrowserByURL {
    
    NSString *url = @"balabala://NHWebBrowser/initWithUrlParams:?url=http://baidu.com";
    UIViewController *ctr = [[PBMediator shared] nativeCallWithURL:[NSURL URLWithString:url]];
    [self.navigationController pushViewController:ctr animated:true];
    
}

2-分类实现方式

- (void)callNativeWebBrowserByCategory {
    
    UIViewController *ctr = [[PBMediator shared] wb_calledByTitle:@"baidu" withUrl:@"http://github.com/iFindTA/"];
    [self.navigationController pushViewController:ctr animated:true];
}
参考

路由跳转的思考 iOS 组件化方案探索