clayallsopp/routable-ios
소개
Routable은 iOS용 앱 내 네이티브 URL 라우터입니다
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -2
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalRoutable

Routable is an in-app native URL router, for iOS. Also available for Android.
Usage
Set up your app's router and URLs (usually done in application:didFinishLaunchingWithOptions:):
[[Routable sharedRouter] map:@"users/:id" toController:[UserController class]];
// Requires an instance of UINavigationController to open UIViewControllers
[[Routable sharedRouter] setNavigationController:aNavigationController];
Implement initWithRouterParams: in your UIViewController subclass:
@implementation UserController
// params will be non-nil
- (id)initWithRouterParams:(NSDictionary *)params {
if ((self = [self initWithNibName:nil bundle:nil])) {
self.userId = [params objectForKey:@"id"];
}
return self;
}
Then, anywhere else in your app, open a URL:
NSString *aUrl = @"users/4";
[[Routable sharedRouter] open:aUrl];
If you wish to do custom allocation of a controller, you can use +allocWithRouterParams:
[[Routable sharedRouter] map:@"users/:id" toController:[StoryboardController class]];
@implementation StoryboardController
+ (id)allocWithRouterParams:(NSDictionary *)params {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
StoryboardController *instance = [storyboard instantiateViewControllerWithIdentifier:@"sbController"];
instance.userId = [params objectForKey:@"id"];
return instance;
}
Set ignoresExceptions to YES to NOT throw exceptions (suggested for a Release/Distribution version)
[[Routable sharedRouter] setIgnoresExceptions:YES];
Installation
CocoaPods
pod 'Routable', '~> 0.1.1'
#import <Routable/Routable.h>
If you're not able to use CocoaPods, please install Routable as a git submodule and add the files to your Xcode project.
Features
Anonymous Callbacks
You can invoke anonymous callbacks with Routable:
[[Routable sharedRouter] map:@"invalidate/:id" toCallback:^(NSDictionary *params) {
[Cache invalidate: [params objectForKey:@"id"]]];
}];
[[Routable sharedRouter] open:@"invalidate/5h1b2bs"];
Presentation Options
You can configure if and how a UIViewController is presented modally with UPRouterOptions:
UPRouterOptions *options = [[UPRouterOptions modal] withPresentationStyle: UIModalPresentationFormSheet];
[self.router map:@"info" toController:[InfoController class]
withOptions:options];
UPRouterOptions has the following DSL setters:
modalwithPresentationStyle:withTransitionStyle:forDefaultParams:
Open External URLs
Sometimes you want to open a URL outside of your app, like a YouTube URL or open a web URL in the browser. You can use Routable to do that:
[[Routable sharedRouter] openExternal:@"http://www.youtube.com/watch?v=oHg5SJYRHA0"];
Multiple Routers
If you need to use multiple routers, simply create new instances of Router:
UPRouter *adminRouter = [Routable newRouter];
[adminRouter map:@"profile" toController: [AdminProfile class]];
UPRouter *userRouter = [Routable newRouter];
[userRouter map:@"profile" toController: [UserProfile class]];
Contact
Clay Allsopp (http://clayallsopp.com)
License
Routable for iOS is available under the MIT license. See the LICENSE file for more info.
관련 프로젝트 살펴보기
불러오는 중…