在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:clayallsopp/routable-ios开源软件地址:https://github.com/clayallsopp/routable-ios开源编程语言:Objective-C 98.9%开源软件介绍:RoutableRoutable is an in-app native URL router, for iOS. Also available for Android. UsageSet up your app's router and URLs (usually done in [[Routable sharedRouter] map:@"users/:id" toController:[UserController class]];
// Requires an instance of UINavigationController to open UIViewControllers
[[Routable sharedRouter] setNavigationController:aNavigationController]; Implement @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 [[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 [[Routable sharedRouter] setIgnoresExceptions:YES]; InstallationCocoaPodspod '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. FeaturesAnonymous CallbacksYou 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 OptionsYou can configure if and how a UPRouterOptions *options = [[UPRouterOptions modal] withPresentationStyle: UIModalPresentationFormSheet];
[self.router map:@"info" toController:[InfoController class]
withOptions:options];
Open External URLsSometimes 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 RoutersIf you need to use multiple routers, simply create new instances of UPRouter *adminRouter = [Routable newRouter];
[adminRouter map:@"profile" toController: [AdminProfile class]];
UPRouter *userRouter = [Routable newRouter];
[userRouter map:@"profile" toController: [UserProfile class]]; ContactClay Allsopp (http://clayallsopp.com) LicenseRoutable for iOS is available under the MIT license. See the LICENSE file for more info. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论