routable-ios icon indicating copy to clipboard operation
routable-ios copied to clipboard

open should handle NSURL type

Open NotMyself opened this issue 11 years ago • 10 comments

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.

NotMyself avatar Nov 04 '13 20:11 NotMyself

It would be! I'd love a PR for it, like UPRouter#openURL?

clayallsopp avatar Nov 05 '13 05:11 clayallsopp

Sure, I'll give it a go sometime this week.

NotMyself avatar Nov 05 '13 16:11 NotMyself

if app is tabbarController based , how will it work ? I am thinking the problem.

aelam avatar Dec 03 '13 03:12 aelam

@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 avatar Dec 03 '13 17:12 clayallsopp

@clayallsopp How about

[[Routable sharedRouter] map:@"invalidate/:id" toCallback:^(NSDictionary *params) {
     // preactions like tabBarController changes
} toController:[MyViewController Class]];

aelam avatar Dec 04 '13 09:12 aelam

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 avatar Dec 04 '13 17:12 clayallsopp

@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.

aelam avatar Dec 05 '13 02:12 aelam

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 avatar Aug 11 '14 23:08 NorthStar

@NorthStar You mean something like [router open:@"some/url" withExtras: @{@"something": else}]? I can see that being handy

clayallsopp avatar Aug 15 '14 04:08 clayallsopp

Yes. Maybe a bit like what an earlier fork added: support extra default params. (Dis)claimer: I do work there.

NorthStar avatar Aug 15 '14 17:08 NorthStar