0

I'm trying to implement a job search App. The results are shown to the user in a UITableView. When a user clicks on a cell, it should open the original Job announcement. To do this, i implemented the following method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *url = [[NSString alloc]init];
    url=[[[xmlParser jobs] objectAtIndex:indexPath.row] urlAddress]; //UrlAddress is an instance variable of type NSString
    NSURL *urlJobDetail = [NSURL URLWithString:(url)];

    [[UIApplication sharedApplication] openURL: urlJobDetail];
}

The interesting part is: if i type an NSString like @"http://www.google.com" or any other link, it works. But when i try to open a "the urlJobDetail", it just doesn't work... Nothing happens at all...

And i searched it in stackoverflow.com and found this:

url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Than the url works but this method changes the original url address and adds lots of % signs like: "http://www.google.com%20 %20 %20" So i get an page not found error.

I don't understand why this function doesn't accept a regular NSString variable as?

I checked it with NSLog and the url seems to be perfectly in order.

Any help would be much, very much appreciated !

Thanks in advance

Zer0
  • 113
  • 10

1 Answers1

1

Because it's URL specification related restrictions

Spaces and control characters in URLs must be escaped for transmission in HTTP, as must other disallowed characters... It is necessary to encode any characters disallowed in a URL, including spaces and other binary data not in the allowed character set, using the standard convention of the "%" character followed by two hexadecimal digits.

  • Hi,thank you for your answer but i don't fully get it... If the escape changes the URL and so that i can not open the URL that I want, how does that help me ? Is there a way to open the URL ? – Zer0 Oct 19 '12 at 09:59