Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Calcuccino Programmers' Calculator
($2.99)

DataFon(Build Apps on Windows)
(free)

Infinote Pinboard for Todos and Notes
(free)

picplz
(free)

poG
($2.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-16-2008, 08:37 AM   #1 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 57
Default application: handleOpenURL: problem

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?
mipegs is offline   Reply With Quote
Old 12-16-2008, 08:42 AM   #2 (permalink)
Registered Member
 
bharath2020's Avatar
 
Join Date: Oct 2008
Location: Bengaluru
Posts: 134
Default application: handleOpenURL: problem

Could you please post code snippet of this.

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..
bharath2020 is offline   Reply With Quote
Old 12-16-2008, 08:58 AM   #3 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 57
Default

Ok, here are the codes:

ApplicationDelegate class
the property is declared as follows:

Code:
 
AppInvocationData *appInvocationData;
@property (nonatomic, retain) AppInvocationData *appInvocationData;
Code:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
	if ([[url scheme] isEqualToString:@"myUrlScheme"]) {
		NSString *urlString = [url scheme];
		AppInvocationData *invData = [[AppInvocationData alloc] initWithParameters:urlString];
		self.appInvocationData = invData;
		[invData release];
		
		return YES;
	}
	return NO;
}


In the view I handle the data as follows in the viewDidLoad method:

Code:
	
IPhoneClientAppDelegate *appDelegate = (IPhoneClientAppDelegate *) [[UIApplication sharedApplication] delegate];
	AppInvocationData *appInvData = appDelegate.appInvocationData;
	if (appInvData) {
		//TODO -site
		self.txtMeetingUserName.text = appInvData.userName;
		self.txtMeetingId.text = appInvData.meetingId;
		self.txtMeetingPass.text = appInvData.meetingPassword;
	}


When I do something like this:

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
	//test
	NSString *testString = @"myUrlScheme://url_here_...";
	NSURL *url = [NSURL URLWithString:testString];
	[self application:application handleOpenURL:url];
             //test
	
	eventOperationQueue = [[NSOperationQueue alloc] init];
	
	[window addSubview:mainNavigationController.view];
	[window setAutoresizesSubviews:YES];
	[window makeKeyAndVisible];
}
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.
mipegs is offline   Reply With Quote
Old 12-16-2008, 10:07 AM   #4 (permalink)
Registered Member
 
bharath2020's Avatar
 
Join Date: Oct 2008
Location: Bengaluru
Posts: 134
Default application: handleOpenURL: problem

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.
bharath2020 is offline   Reply With Quote
Old 12-16-2008, 10:19 AM   #5 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 57
Default

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?
mipegs is offline   Reply With Quote
Old 12-16-2008, 10:24 AM   #6 (permalink)
Registered Member
 
bharath2020's Avatar
 
Join Date: Oct 2008
Location: Bengaluru
Posts: 134
Default application: handleOpenURL: problem

Not exactly the same code, but yes the same logic.. I presume you the string "myURLScheme" is just a placeholder here, right?

Which URL's did you register for?

For debugging, here is caveman approach.. use NSLog inside you if statement..
bharath2020 is offline   Reply With Quote
Old 12-16-2008, 10:30 AM   #7 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 57
Default

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?
mipegs is offline   Reply With Quote
Old 12-16-2008, 10:32 AM   #8 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 57
Default

Here is the URL I registered for (if it helps...):
tmeet://site_url=http://www.site.net&user_name=User%20Name&
id=2234566&password=hello123
mipegs is offline   Reply With Quote
Old 12-16-2008, 10:36 AM   #9 (permalink)
Registered Member
 
bharath2020's Avatar
 
Join Date: Oct 2008
Location: Bengaluru
Posts: 134
Default application: handleOpenURL: problem

Replace @"myURLscheme" with string @"tmeet", I think here is the bug.

Run the application in your simulator by typing the URL in you safari. (Make sure you have loaded the latest bundle in your simulator).

You can view logs in your Console application. Spotlight Console

HTH

Bharath
bharath2020 is offline   Reply With Quote
Old 12-16-2008, 10:43 AM   #10 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 57
Default

Quote:
Replace @"myURLscheme" with string @"tmeet", I think here is the bug.
I did it correctly . myURLscheme was only placeholder for tmeet. In my application it's correctly .

Ok, I'll try to debug it using console output and tomorrow I'll write if i managed to solve the issue.
mipegs is offline   Reply With Quote
Old 12-17-2008, 05:17 AM   #11 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 57
Default

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.

Thanks for help!
mipegs is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 51,375
Threads: 52,831
Posts: 225,479
Top Poster: BrianSlick (3,576)
Welcome to our newest member, darrentousignant
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:32 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0