I need to support custom URL scheme. I did something like that:
I implemented application: handleOpenURL: method in my application delegate class. The method parses the URL string and sets object with parsed data as a property in the delegate object. Later, in viewDidLoad method of the first view i try to access the delegate's property and... the property is nil! Unfortunately i can't debug what's wrong.
When I prepared NSURL object with the same link in applicationDidFinishLaunching: method and invoked application: handleOpenURL: method by hand everything worked great!
So there must by a problem with method invocation order. Am I correct?
How to solve this issue?
May be there are chance that your Objects, to which you are setting the property value, in the NIB or xib or not yet instantiated. it just a guess.. coz i had face it many times..
everything is beeing processed correctly.
I'm sure that the url link i processed in the application: handleOpenURL method because when i place [application terminateWithSuccess] code there the app quits.
Well, your code looks fine. Just ensure whether it enter your if condition in you application:handleURL: method. I did write a test case and tested in simulator and it worked fine.
Did you do the same as i did? And it worked? So what maight be the problem in my case... I'm sure that the code in application: handleOpenURL is processed.
By the way, do you know any way how to debug this? I don't know, some kind of logging or something?
The url is not the case. The application starts when i click prepared link in safari browser.
You said that I can use NSLog - but wher can I see the output? To test the case I need to deploy the app on simulator and then press home button and go to safari. Then click the prepared link and my app starts. So where can I see NSLog output?
I've managed to solve my issue using Application Console. It's allways good to find out that there is a cool stuff around (like Application Console).
As I find out the problem was in method invocation order:
So the order was:
delegate method: applicationDidFinishLaunching:
first view controller method: viewDidLoad:
delegate method: application: handleOpneUrl
So, the object accessed in viewDidLoad method was nil because it was not created yet.