clayallsopp / routable-ios Goto Github PK
View Code? Open in Web Editor NEWRoutable, an in-app native URL router, for iOS
License: MIT License
Routable, an in-app native URL router, for iOS
License: MIT License
The above code in the Swift how to write
Hi, I am trying to use Routable to handle external schema based links. For example, someone clicks a link to myapp://recipies/42. I am currently handling this in my app delegate by implementing application:handleOpenUrl like this:
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSString *path = [url.absoluteString substringFromIndex:NSMaxRange([url.absoluteString rangeOfString:@"://"])];
[[Routable sharedRouter] open:[path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
return YES;
}
It would be awesome, if i could simply hand off the NSURL to the router and have it do the right thing.
In the view controllers in the example app:
UIButton *modal = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[modal setTitle:@"Modal" forState:UIControlStateNormal];
[modal addTarget:self action:@selector(tapped:) forControlEvents:UIControlEventTouchUpInside];
[modal sizeToFit];
This makes the frame right under nav bar, and therefore not seen or usable.
All tests pass fine when run in iOS 7, but in iOS 8 the above tests fails on the assert
XCTAssertTrue([USER_ID isEqualToString:@" "], @"Should have an empty ID");
It looks like USER_ID is coming through as an empty string. I tried poking around, but couldn't see why this would be happening.
Hi, just curious—any plan to cut a 0.1.2 with @NorthStar 's (and others') changes included? ATM I'm using :head in my Podfile which always makes me nervous.
Thanks!
is this intentional or a bug?
If -Weverything is added to the LLVM flags, a warning will be shown for signed integers being used for unsigned values.
I'm using UITabBarController,each tabbar item is UINavigationController,so I have 4 tabbar items and 4 UINavigationControllers, how can i setNavigationController?
I am trying to map multiple URLs to the same controller but the router just uses the first one it finds. Consider opening the following URL in the example below: "example/new/test".
[[Routable sharedRouter] map:@"example/new/:param1" toController:[Example class]];
[[Routable sharedRouter] map:@"example/:param1/:param2" toController:[Example class]];
What I would expect to happen is my controller will be initialized with the first mapping and param1 being set to "test" but it actually opens the second mapping with param1 being set to "new" and param2 being set to "test". I believe this is a caching issue and it doesn't consider all scenarios of the mappings.
Any advice? Thanks!
An extra parameter could be call back or any data. It looks something like:
- (void)open:(NSString *)url
extraDefaultParams:(NSDictionary *)extraDefaultParams
animated:(BOOL)animated;
Use case:
//.... in a viewController.m
[self updateUserInfo];
[[Routable sharedRouter] open:@"base/settings"
extraDefaultParams:@{@"newTitle": self.userTitle}
animated: YES];
I will try to be more creative in the sample app.
can't support standard scheme URL?such as a url begining with "APPName://" or containing "?key1=value1&&key2=value2"
Hey Clay,
Nice stuff, this is cool code. Thanks for making it available!
How would you handle thinks like "routing exceptions"? But that I don't mean thrown exceptions, but rather something "show the /users/:id mapped view controller in a modal EXCEPT if some condition holds, then show it in some other way". For example, if something in a nav controller already showing in a modal asks to show the users controller in a modal, maybe the users controller should just be pushed on the stack of the nav controller inside the existing modal, instead of dismissing or presenting another modal ...
Thoughts?
I'd be happy to help with a PR, but I'm just curious as to your thoughts on this because this is such a nicely-architected piece of code.
Thanks.
There are several reasons for using idiomatic modern Objective-C in Routable, including improved readability and easier maintenance. So I propose that you consider a pull request I am about to send by the end of today.
Many of my concerns are style-related even though the caveats in usage are small. While the changed Routable-iOS obscures the parallelism between its Android counterparts, using alloc to allocate memory and init or custom init is preferred over 'new' or a custom 'new' in modern Objective-C, for instance.
@implementation Routable
static Routable *_sharedRouter = nil;
+ (Routable *)sharedRouter {
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedRouter = [[Routable alloc] init];
});
return _sharedRouter;
}
This shows what I'd like to use.
I understand that the current implementation might be more helpful to many. I am in no way a master at this but I think more Objective-C programmers think like me; I can merely propose this change to you with no attached authority.
(Meanwhile, here is my personal motivation: I have changed my fork greatly. It would be hard for me to continue using the library's future updates if the library does not change its style.)
Is it possible to DeepLink to Apps which are not Installed yet?
0.0.4 generates the following Undeclared selector warnings:
Undeclared selector 'controllerWithRouterParams:'
in Routable.m on line 300
Undeclared selector 'controllerWithRouterParams:'
in Routable.m on line 301
Undeclared selector 'initWithRouterParams:'
in Routable.m on line 305
Undeclared selector 'initWithRouterParams:'
in Routable.m on line 306
Undeclared selector 'controllerWithRouterParams:'
in Routable.m on line 316
Undeclared selector 'initWithRouterParams:'
in Routable.m on line 316
Perhaps make these optional protocol methods for the implementing class?
UIKit isn't imported in the routable header, which makes it uncompilable when the files are dragged into your project. Is there any reason not to import?
hi man ,
why not add a method just like 'map:(NSString *)format toController:(NSString *)controllerClassName', so that the user don't need to add 'import "ControllerClass.h"'
3ks
It seems the change in 56c1c0d to use url.pathComponents to split a url into parameters has the unexpected side effect of removing empty components. I'm not sure if empty components are supposed to be supported, but I had been using the library that way. The pathComponents documentation states "Empty components (caused by consecutive path separators) are deleted." (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/pathComponents)
So if I have a route "test/:param1/:param2" and try to go to url "test//foo", in previous versions, I'd get param1 = "" and param2 = "foo". Now I get a "Route not found" exception because the code thinks I passed in a route with only 2 components.
For example, I open specific view controller and then perform some code in callback block for the mapping URL.
I read the code and found that you can only do one of the callback and view controller and return.
This is a feature I could use and was wondering if it makes sense to add?
Something like
[self.navigationController setViewControllers:@[controller] animated:YES];
I have a slide-out menu and I would like to open view controllers as the root of my navigation controller instead of pushing new controllers on to the stack whenever a menu item is selected.
if I want to use tabBarController as rootVeiwController,What should I do? please
Is possible to use it with a storyboard?
When using a route with params:
- (id)initWithRouterParams:(NSDictionary *)params {
UIStoryboard *b = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
if ((self = [self initWithNibName:nil bundle:nil])) {
self.params = params;
}
return self;
}
if use instantiateViewControllerWithIdentifier it gets a crash in
controller = [controller performSelector:CONTROLLER_SELECTOR withObject:[params getControllerParams]];
I have a controller that is shared by several routers:
UPRouter *router = [Routable sharedRouter];
UPRouter *routerEdit = [self editRouter];
UPRouterOptions *order = [self paramOrder:@"O"];
UPRouterOptions *invoice = [self paramOrder:@"I"];
[router map:@"invoices" toController:[OrderListViewController class] withOptions:invoice];
[routerEdit map:@"invoices/:id" toController:[POSViewController class] withOptions:invoice];
[router map:@"orders" toController:[OrderListViewController class] withOptions:order];
[routerEdit map:@"orders/:id" toController:[POSViewController class] withOptions:order];
In this order if I go to "invoices/0" the POSViewController is called, but If I go to "invoices" also go to POSViewController!. If I reverse the order:
[routerEdit map:@"invoices/:id" toController:[POSViewController class]
[router map:@"invoices" toController:[OrderListViewController class] withOptions:invoice];
Then both go to OrderListViewController.
PD: I try with 2 routers (router & routerEdit) but happend equal with only one.
I need the new custom transitions in ios 7 how would I do this ?
Are we able to pass url query parameters?
ie. example://test/2?abc=2¶m2=3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.