LJURLRouter 1.0.3

LJURLRouter 1.0.3

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布上次发布2015年12月

liaojinxing 维护。



  • Liao Jinxing 编写

任何iOS对象都可以使用URL Router。

为什么还需要另一个路由器

已经有了很多开源的路由器,为什么还要再制造一个呢?

其他路由器几乎都是限制在controller或block上,而LJURLRouter可以路由任何对象。

使用场景

  • 在某些情况下,使用URL表示对象与服务器通信可以减少网络流量。

  • 只需打开URL进行控制器导航,而无需导入控制器头文件并调用pushViewController...

  • 除了应用内的导航,还可以轻松处理url schema、deep link、3D Touch、spotlight search等导航。

如何使用

注册URL映射

注册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&param2=world"];

UIViewController分类

LJURLRouter还提供了一个用于方便使用的UIViewController分类。

[controller openURL:@"/profile/123?param1=hello&param2=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 等跳转

使用方法

注册URL和class的映射关系

[[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&param2=world"];

UIViewController 分类

提供 UIViewController 的分类,便于进行控制器之间的跳转

[controller openURL:@"/profile/123?param1=hello&param2=world"]

其他特性

  • LJURLRouter 支持默认 schema

  • 更详细的使用方法,请参阅 demo 和单元测试

安装

可以直接将源代码放到你的工程中,或者使用 CocoaPods

pod 'LJURLRouter'

许可证

MIT