routable-ios
routable-ios copied to clipboard
open should handle NSURL type
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.
It would be! I'd love a PR for it, like UPRouter#openURL
?
Sure, I'll give it a go sometime this week.
if app is tabbarController based , how will it work ? I am thinking the problem.
@aelam UITabBarController isn't well-supported within Routable right now. You could definitely use anonymous callbacks for now, but would welcome a PR that adds them as a first-class citizen
@clayallsopp How about
[[Routable sharedRouter] map:@"invalidate/:id" toCallback:^(NSDictionary *params) {
// preactions like tabBarController changes
} toController:[MyViewController Class]];
Hm so toCallback
is sort of like a before filter? That would be cool, would prefer the order to be swapped and renamed
[[Routable sharedRouter] map:@"invalidate/:id" toController:[MyViewController Class] withBeforeCallback:^(NSDictionary *params) {
// preactions like tabBarController changes
} ];
@clayallsopp
[[Routable sharedRouter] map:@"invalidate/:id" toController:[MyViewController Class] withBeforeCallback:^(NSDictionary *params) {
// preactions like tabBarController changes
} ];
I was aware of that if just add an withBeforeCallback block,Routable can't present a MyViewController or present a NavigationController with a rootController which is MyViewController [or show a view in keyWindow(like a loginView) ] in this case, it's not flexible than original anonymous callbacks
[[Routable sharedRouter] map:@"invalidate/:id" toCallback:^(NSDictionary *params) {
[Cache invalidate: [params objectForKey:@"id"]]];
}];
as we know android has IntentFilter
, it can show a dialog like share dialog,if there is a way to add the "IntentFilter" to decide present or push, and an animation to customise, and then toController, or even a view Class(loginView), that would be wonderful . It seems I think too much but without good idea
Anyway -[Routable map: toCallback:]
and -[Routable map:@"invalidate/:id" toController:]
are good for most cases.
I have been thinking of having both callback block & view controller presentation as well, though I am not sure how it would work, especially with storyboards.
On the note of tab bar, has taking more parameters(on top of default params) been considered to allow a multiplied number of states per view controller?
That extra param can be a block that's invoked once a done button is pressed, for instance, so it is tangentially related to the discussion.
@NorthStar You mean something like [router open:@"some/url" withExtras: @{@"something": else}]
? I can see that being handy
Yes. Maybe a bit like what an earlier fork added: support extra default params. (Dis)claimer: I do work there.