iphonethree20ttnavigator

Is there a way to register a url with query params in Three20?


I have a url with a varying number of query params:

myapp://profile?username=1&status=2&title=3

I would like to register something like this with TTUrlMap

[map from:@"myapp://profile*" toViewController:[ProfileController class]];

And I would like Three20 to recognize the "rest of the url" and either invoke something like:

initWithOriginalUrl:(NSString*) originalUrl

where I can then parse the query params or:

initWithQueryParams(NSDictionary*) queryParams 

where TTNavigator has recognized my url, parsed the params into a map and then invoked my controller passing the query params?

Is this supported? I would rather not pass the encoded url as a param as was suggested here: Pass URL Question


Solution

  • I'm going to answer this myself - the trick is knowing about initWithNavigatorURL - Three20 will parse your query params, call this method and pass the parsed params to it if you haven't explicitly set a method in your map. So the solution is to add this to your map:

    [map from:@"myapp://profile" toViewController:[ProfileController class]];
    

    and implement the magic initWithNavigatorUrl method on your toViewController

    @implementation ProfileController
    
    - (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
        NSLog(@"ProfileController initWithNavigatorUrl %@, %@", URL, query);  
        ....