Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

handleOpenURL not called

mkzeromkzero Posts: 5
edited August 2010 in iPhone SDK Development
Hi everybody,
hopefully someone can help me solve this problem.
I implemented a Custom URL Scheme to start my app through a link out of an email. This part works fine and the app gets called without any problems.
The great thing about this schemes is that you can extend the scheme with a link and use this to get some files into your app.
for example: myapp:http://mypage.com/info.xml

All this is supposed to be handled in the
-(BOOL)application: (UIApplication *)application handleOpenURL: (NSURL *)url;
Unfortunately this never gets called in my delegate.

Someone posted a question concerning this problem but it turned out to be just a timing problem. In my case I am sure that it is no timing problem.

I tried to find any posts about similar problems but there aren't too many and the ones discussing my problem are not solved.
So if anyone could help me I would be more than happy because this stuff really drives me crazy.
Post edited by mkzero on

Replies

  • mkzeromkzero Posts: 5
    edited October 2009
    Can anybody tell me whether there is something I can really do wrong with this method?
    Do I have to implement a special framework or do I have to include a delegate protocol or something like this?
    Does it have to be a special delegate?
    I am happy with any help I can get because I really need to get this thing working and if the method is not called I am in trouble.
    If anyone knows another way to check the link in another method that would also be great.
    I wrote a mail to apple but no reply yet.
    Ok enough desparation ;-)
  • mkzeromkzero Posts: 5
    edited October 2009
    Ok got it working myself ;-)
    I don't know why it didn't work out but if one uses the
    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
    
    instead of standard didFinishLaunching you can access an eventually passed URL and the Bundle ID of the app which executed your URL scheme. This is even better than the standard version. :-D
    If I didn't get it wrong in the documentation files from apple it is even recommended by apple to use this method.

    Here is my code in the delegate and maybe someone else can use it as well ;-)
    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    	NSArray *keyArray = [launchOptions allKeys];
    	if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) {
    		NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
    		m_URLString = [url absoluteString];
    		UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Hello" message:m_URLString delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil]; 
    		[alert show];
    		[alert release];
    		[window addSubview:viewController.view];
    		[window makeKeyAndVisible];
    		return YES;
    	}
    	[window addSubview:viewController.view];
    	[window makeKeyAndVisible];
    	return YES;
    }
    

    The Bundle ID would be the second key in the array.
    When the app gets called it starts as usual and if someone uses the URL scheme you can access the info inside the if clause.
  • vertinevertine Posts: 80Registered Users
    edited April 2010
    hey all, i am struggling with this today. I have a callback from Flickr after i pass a successful frob auth. My app relaunches as expected from the Flickr callback, but i can not capture the handleOpenURL delegate method on the relaunch . i know it is not working becuase i have both an UIAlertView ready to pop and i can see in the Console.app that it's not happening. I will not however, just when we are redirected to Flickr to authenticate, i get this message:
    URL scheme 'myurlschem' is reserved. Ignoring registrtation attempt by com.myapplicationdomain.myapp.
    

    could that be lead?
  • greenflamegreenflame Posts: 54Registered Users
    edited April 2010
    Anyone?!
    <a href="http://itunes.apple.com/au/app/easy-light/id318572731?mt=8" target="_blank">Easy Light</a> - The simple, easy torch solution for the iPhone.<br />
    <a href="http://itunes.apple.com/au/app/track-tram/id323787097?mt=8" target="_blank">Track-a-tram<
  • Duncan CDuncan C Posts: 9,020Tutorial Authors, Registered Users @ @ @ @ @ @ @
    edited August 2010
    vertine wrote: »
    hey all, i am struggling with this today. I have a callback from Flickr after i pass a successful frob auth. My app relaunches as expected from the Flickr callback, but i can not capture the handleOpenURL delegate method on the relaunch . i know it is not working becuase i have both an UIAlertView ready to pop and i can see in the Console.app that it's not happening. I will not however, just when we are redirected to Flickr to authenticate, i get this message:
    URL scheme 'myurlschem' is reserved. Ignoring registrtation attempt by com.myapplicationdomain.myapp.
    

    could that be lead?

    Yes, that is your problem. "myurlschem" is a placeholder. you should replace that with a unique URL scheme, like "FooBarURL", or "vertine", or whatever. Note that the message also indicates that you never changed the default app ID from com.myapplicationdomain.myapp. That's also going to get you in trouble.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • Duncan CDuncan C Posts: 9,020Tutorial Authors, Registered Users @ @ @ @ @ @ @
    edited August 2010
    mkzero wrote: »
    Ok got it working myself ;-)
    I don't know why it didn't work out but if one uses the
    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
    
    instead of standard didFinishLaunching you can access an eventually passed URL and the Bundle ID of the app which executed your URL scheme. This is even better than the standard version. :-D
    If I didn't get it wrong in the documentation files from apple it is even recommended by apple to use this method.

    Here is my code in the delegate and maybe someone else can use it as well ;-)
    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    	NSArray *keyArray = [launchOptions allKeys];
    	if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil) {
    		NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
    		m_URLString = [url absoluteString];
    		UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Hello" message:m_URLString delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil]; 
    		[alert show];
    		[alert release];
    		[window addSubview:viewController.view];
    		[window makeKeyAndVisible];
    		return YES;
    	}
    	[window addSubview:viewController.view];
    	[window makeKeyAndVisible];
    	return YES;
    }
    

    The Bundle ID would be the second key in the array.
    When the app gets called it starts as usual and if someone uses the URL scheme you can access the info inside the if clause.

    Note that this code is not going to be reliable. The NSDictionary method allKeys does not guarantee the order of the keys it returns. So the URL might be at index 0 today and a different index tomorrow.

    To quote the documentation on the allKeys method:
    The order of the elements in the array is not defined.


    Instead, you should use this code:
    NSURL *url = [launchOptions objectForKey: UIApplicationLaunchOptionsURLKey];
    
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
Sign In or Register to comment.