-3
NSString *urlAddress = [NSString stringWithFormat:@"http://www.domain.com?input=%@",[alertView textFieldAtIndex:0].text];
NSURL *myUrl = [NSURL URLWithString:[urlAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *openURL = [NSString stringWithContentsOfURL:myUrl encoding:NSUTF8StringEncoding error:NULL];
NSLog(@"%@",openURL);

openUrl is always returning (null), probably because of the encoding, but I don't know how to fix it.

Larme
  • 24,190
  • 6
  • 51
  • 81
Berendschot
  • 3,026
  • 1
  • 21
  • 43

2 Answers2

1

Double check these three things:

  • Check that the URL which you are pointing to is a valid URL. The null value could be a result of an invalid URL.
  • Catch the NSError which the stringWithContentsOfURL throws. That will give you some insight on what is wrong.
  • Like you suspect, try changing the string encoding.
aksh1t
  • 5,410
  • 1
  • 37
  • 55
0
NSError *error;
NSString *urlString = [NSString stringWithFormat:@"http://www.domain.com?input=%@", stringVariable];
NSURL *urlAdress = [NSURL URLWithString:urlString];
NSString *urlContent = [[NSString alloc] initWithContentsOfURL:urlAdress encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@", urlContent);

This works fine, the problem was an failing internet connection.

Berendschot
  • 3,026
  • 1
  • 21
  • 43