任何iOS对象都可以使用URL Router。
已经有了很多开源的路由器,为什么还要再制造一个呢?
其他路由器几乎都是限制在controller或block上,而LJURLRouter可以路由任何对象。
在某些情况下,使用URL表示对象与服务器通信可以减少网络流量。
只需打开URL进行控制器导航,而无需导入控制器头文件并调用pushViewController...
除了应用内的导航,还可以轻松处理url schema、deep link、3D Touch、spotlight search等导航。
注册URL格式和匹配的类。
[[LJURLRouter sharedRouter] registerURL:YOUR_URL_FORMAT forClass:[YOUR_CLASS_NAME class]];
例如
[[LJURLRouter sharedRouter] registerURL:@"/profile/:profile_id" forClass:[ProfileViewController class]];
从URL获取匹配的对象实例。参数将被自动解析
id instance = [[LJURLRouter sharedRouter] instanceWithRouteURL:YOUR_URL_HERE];
例如
id instance = [[LJURLRouter sharedRouter] instanceWithRouteURL:@"/profile/123?param1=hello¶m2=world"];
LJURLRouter还提供了一个用于方便使用的UIViewController分类。
[controller openURL:@"/profile/123?param1=hello¶m2=world"]
也支持默认的schema。
UIViewController分类支持多种路由类型,包括导航控制器中的push和present。
更多详情请查看示例项目和单元测试。
将源文件拖入你的项目中。
或者使用cocoapods。以下是你的podfile的示例:
pod 'LJURLRouter'
LJURLRouter是在MIT许可下发行的。更多信息请参阅LICENSE文件。
开源社区已经有很多不错的服务器,但并不满足需求。
很多实现都是限制在controller和block上,LJURLRouter主要是用于对象的映射,支持任意class.
与服务器通信时,很多情况下无法直接传递对象,或者为了节省流量,可以通过定义一套url routing协议来进行通信。例如使用/user/123 代表123这个user,而无需返回一个user对象。
处理端内页面的跳转时,可以直接openURL,而无需导入控制器,再pushViewController
可以轻松地处理推送通知, url schema, deep link, 3D Touch, spotlight search 等跳转
[[LJURLRouter sharedRouter] registerURL:YOUR_URL_FORMAT forClass:[YOUR_CLASS_NAME class]];
示例
[[LJURLRouter sharedRouter] registerURL:@"/profile/:profile_id" forClass:[ProfileViewController class]];
id instance = [[LJURLRouter sharedRouter] instanceWithRouteURL:YOUR_URL_HERE];
示例
id instance = [[LJURLRouter sharedRouter] instanceWithRouteURL:@"/profile/123?param1=hello¶m2=world"];
提供 UIViewController 的分类,便于进行控制器之间的跳转
[controller openURL:@"/profile/123?param1=hello¶m2=world"]
LJURLRouter 支持默认 schema
更详细的使用方法,请参阅 demo 和单元测试
可以直接将源代码放到你的工程中,或者使用 CocoaPods
pod 'LJURLRouter'
MIT