Jump to content

iPhone SDK: Got some questions about urlString...


3 posts in this topic

Recommended Posts

I've got two problem left with my app that I can't figure out. Looked through all of the documentation & can't seem to find the answer.

 

1) Can't search more than 1 word queries. Here's the code that I have for searching a site

 

- (void)searchBarTextDidEndEditing:(UISearchBar *)mySearchBar
{
//•• start your search!
UIApplication *app = [UIApplication sharedApplication];
NSString *nameString = self.mySearchBar.text;

NSString *urlString = [NSString stringWithFormat:@"Site that I am searching", nameString];
NSURL *url = [NSURL URLWithString:urlString];

[app openURL:url];
}

 

When I emailed Apple's Dev Tech Support, they said

I think you might need to precent-escape all spaces when constructing the URL for searching (%20) should be replaced by the space. There are APIs in NSURL

and NSString that help you do this.

 

I looked all through any documentation relating to NSURL & NSString & couldn't find anything related to that.

 

2) And when I do have a valid query entered, any other buttons on the app, like a button to the "About" page, initializes the search process.

 

Apple Dev Tech Support suggested this

Set some break points in your code and find out who is starting the search.

 

How exactly would I do that? Any help related to either problem would be greatly appreciated

Link to comment
Share on other sites

You posted this at MR and someone said this:

1) take a look at the method NSString's stringByAddingPercentEscapesUsingEncoding:

 

2) click on the side of the code to add a breakpoint.

 

I hope it help's you, I'm not sure what it means as I'm just starting out in the coding field but the guy at MR seems to, Check your thread there.

 

Northy

Link to comment
Share on other sites

  • 2 weeks later...

I've got 2 final showstopping bugs left in my app. I've got a RootViewController button leading to an "About" window. A cancel button for my search bar & the search button on my app. These bugs involve:

 

*When no search query is entered, Search & Cancel buttons lock up the app when pressed

*When a search query is entered into the search field, the Cancel & About buttons start the search

 

 

I've set breakpoints & I think I've located the source of the problem but, I'm not sure how to fix the issue. Trying to get this submitted to Apple by 3pm EST

 

I've got a breakpoint set at [app openURL:url] below (RootViewController.m)

- (void)searchBarTextDidEndEditing:(UISearchBar *)mySearchBar
{
//•• start your search!
UIApplication *app = [UIApplication sharedApplication];
NSString *nameString = self.mySearchBar.text;

NSString *urlString = [NSString stringWithFormat:@"Site that I am searching", nameString];

NSString *fixedURL = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // or any other encoding
NSURL *url = [NSURL URLWithString:fixedURL];

[app openURL:url];
}

 

When the About button is pressed (with a search query entered), the app stops debguggin at "return self;" - AboutController.m

 

- (id)init
{
if (self = [super init]) {
	// Initialize your view controller.
	self.title = @"About";
}
return self;
}

 

I think I narrowed the problem down to this section in my "RootViewController.m" file

 

- (id)init
{
if (self = [super init]) {
	// Initialize your view controller.
	self.title = @"My Awesome App";

	UIBarButtonItem* aboutButton = [[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(tellParentToPush)];
	self.navigationItem.rightBarButtonItem = aboutButton;
	[aboutButton release];

}
return self;
}

 

I'm just at a loss on how to fix these last 2 bugs. Any suggestions on how to tackle this problem would be greatly appreciated

Link to comment
Share on other sites

 Share

×
×
  • Create New...