引入
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服務器用來解耦。
這就是路由解耦的本質。