JLRoutes

作者: 事件_666 | 来源:发表于2019-06-04 11:52 被阅读0次

    引入
    pod 'JLRoutes', '~> 2.0.5'

    [[JLRoutes globalRoutes] addRoute:@"/:object/:action/:primaryKey" handler:^BOOL(NSDictionary *parameters) {
    NSString *object = parameters[@"object"];
    NSString *action = parameters[@"action"];
    NSString *primaryKey = parameters[@"primaryKey"];
    // stuff
    return YES;
    }];

    调用
    NSURL *editPost = [NSURL URLWithString:@"myapp://post/edit/123?debug=true&foo=bar"];
    [JLRoutes routeURL:editPost];

    解析
    {
    "object": "post",
    "action": "edit",
    "primaryKey": "123",
    "debug": "true",
    "foo": "bar",
    "JLRouteURL": "myapp://post/edit/123?debug=true&foo=bar",
    "JLRoutePattern": "/:object/:action/:primaryKey",
    "JLRouteScheme": "JLRoutesGlobalRoutesScheme"
    }

    以上是官方给出的实例
    -------------分割线以下是自己想法---------------------

    myapp://post/edit/123?debug=true&foo=bar 这明显是个GET请求
    然而代码总体没有找到搭建get服务器的地方。
    所以完全可以本地搭建一个get服务器(用套接字在app端) 更有利于解耦。
    好 既然有可以搭建GET服务器显然也可以搭建POST服务器,所以可以搭建本地的POST服务器用来解耦。
    这就是路由解耦的本质。

    相关文章

      网友评论

          本文标题:JLRoutes

          本文链接:https://www.haomeiwen.com/subject/ftslxctx.html