Search code examples
objective-cxcodeuiwebview

UIWebView doesn't load content


I don't understand why if I load the content of a UIWebView in XCode this way:

NSString *string = @"http://www.dummyurl.org/dummy.pdf";
NSURL *url = [NSURL URLWithString:string];
[my_view loadRequest:[NSURLRequest requestWithURL:url]];

everything works fine, but if a build the original string from a php script I wrote:

NSString *strURL = [NSSTring stringWithFormat:@"www.myserver.php"];
NSString *string = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:strURL]];
NSURL *url = [NSURL URLWithString:string];
[my_view loadRequest:[NSURLRequest requestWithURL:url]];

nothing works. I checked my script and it returns EXACTLY the original string (http://www.dummyurl.org/dummy.pdf) that works fine with the first method.

I build from a PHP script the content of a UITextView too, but that works fine.
I don't understand why this method works with the UITextView but not with the UIWebView to load the .pdf.


Solution

  • It may be useful

    NSCharacterSet *characterSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSString *tempString = [string stringByTrimmingCharactersInSet:characterSet];
    NSURL *url = [NSURL URLWithString:string];
    [my_view loadRequest:[NSURLRequest requestWithURL:url]];