views:

684

answers:

3

I'm working on a handling a custom URL Scheme in an app and am trying to sort out:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

I'm passing and successfully parsing a URL into an NSDictionary in my app but wondering "what now?" handleOpenURL returns a BOOL but to what? It's hard for me to debug as I haven't figure out how to have debugger running on device when it fires.

All I do know is that applicationDidFinishLaunching completes before handleOpenURL and it appears as though my rootViewController is on screen.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Load data
    [self initializeData]; 
    // Configure and show the window
    [window addSubview:[navigationController view]];    
    [window makeKeyAndVisible];
}

Anyway, so, now I have this NSDictionary object in my appDelegate, how would you pass it to the rootViewController so it can do something with it in its detail view? Would I call

[[navigationController topViewController] addItemWithDictionary:theDictionary];

before handleOpenURL's return YES; Or, should I create an NSDictionary property in my appDelegate and then after "Return YES;" retrieve it from my rootViewController (or detailViewController - haven't worked out which yet). If so what's the trigger? It's not clear to me where handleOpenUrl's returns are heading...and what, if any, value they have to me.

Thanks!

A: 

I think I may have answered my own question but if you have other ideas I'd love to hear them!

I think I need to continue processing in handleOpenURL and turn the dictionary into an object that is then added to my appDelegate's array that rootViewController is using to build it's table view. Obviously need to work out some validation & confirmation on user's part before auto populating array. I guess that would also happen within confines of handleOpenURL?

Meltemi
+1  A: 

Take a look at the suggestion here about didFinishLaunchingWithOptions

http://www.iphonedevsdk.com/forum/iphone-sdk-development/31742-handleopenurl-not-called.html

There are a couple of approaches I've used to pass data around, and depending on the conditions I mix it up.

  1. Keep a global around so you don't have to worry about passing.

  2. Register/post your data using the Observer pattern with a Notification object using the notification message center.

  3. Save URLs to NSUserDefaults (also a dictionary, but you don't have to manage it).

Recently I had to do something similar on a UIWebView and the handling of filtering some URL data. I had to subclass WebViewCache and setSharedCache on the NSURL. I strongly suspect this would apply to your problem as well by retrieving the data with shouldStartLoadWithRequest.

David Sowsy
Very helpful, thanks! But I'm still looking for an answer to who (or what) exactly is calling `handleOpenURL` and what difference a return value of YES or NO makes to that calling object? Seems to make no difference whatsoever from my apps perspective...
Meltemi
A: 

a handy tip for debugging openurl from other apps or mobile safari (non jailbroken device) is to subclass UIApplication and override a few undocumented methods, sorry i dont remember names offhand but you can dig them up at ericasadun.com, the names will be fairly obvious.

when you launch the app through xcode and hit home springboard doesnt kill the process because it was started by xcode (afaik) so you can launch other apps and call openurl while still being attached to the debugger.

drunknbass