Latest 0.2.0
Homepage https://github.com/iFindTA/NHURLRouterPro
License MIT(LICENSE)
Platforms ios 7.0, requires ARC
Frameworks UIKit, Foundation
Authors

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 组件化方案探索

Latest podspec

{
    "name": "PBMediator",
    "version": "0.2.0",
    "summary": "PBMediator is an Objc Wrapper for components communication.",
    "homepage": "https://github.com/iFindTA/NHURLRouterPro",
    "description": "Between componentsu2019s communication over url routes some like flasku2019s route mechanism that warpper by Objc, and for ios",
    "license": "MIT(LICENSE)",
    "authors": {
        "nanhujiaju": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/iFindTA/NHURLRouterPro.git",
        "tag": "0.2.0"
    },
    "source_files": "NHURLRouterPro/PBRouter/**/*",
    "public_header_files": "NHURLRouterPro/PBRouter/**/*.h",
    "frameworks": [
        "UIKit",
        "Foundation"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This