clayallsopp / routable-ios

Routable, an in-app native URL router, for iOS
MIT License
1.8k stars 194 forks source link

open should handle NSURL type #14

Open NotMyself opened 10 years ago

NotMyself commented 10 years ago

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.

clayallsopp commented 10 years ago

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

NotMyself commented 10 years ago

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

aelam commented 10 years ago

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

clayallsopp commented 10 years ago

@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

aelam commented 10 years ago

@clayallsopp How about

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

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
} ];
aelam commented 10 years ago

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

NorthStar commented 10 years ago

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.

clayallsopp commented 10 years ago

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

NorthStar commented 10 years ago

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