0

I'm having an issue with UIWebView when loading a simple html. My code is as follows:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *imageHTML = [NSString stringWithFormat:@"%@%@%@", @"<html><body><img src='", url, @"' alt='URL not found'></body></html>"];
[webView loadHTMLString:imageHTML baseURL:baseURL];

When I deploy this code directly from XCode, my image displays as I expect. However, when I compile the ipa and install the application via the Worklight Application Center, the code does not run, the method webViewDidFinishLoad never occurs. I'm not sure what's wrong here any ideas? The alt does not appear either.

Worklight version 6.1.0-00-20131219-1900, iOS6 and iOS7

EDIT: The same problem occurs without an image

@"<html><body>HelloWorld</body></html>"
Jonathan Sweetman
  • 605
  • 1
  • 6
  • 16

2 Answers2

2

It looks like you need to escape (and fix) your quote characters in the string like this perhaps (I also omitted your first three %@ from your string, as I wasn't sure why they were in there for the question you posted):

NSURL *url = [NSURL URLWithString:@"http://www.foo.com/bar.png"];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *imageHTML = [NSString stringWithFormat:@"<html><body><img src=\"%@\" alt=\"URL not found\"></body></html>", url];

Result:

<html><body><img src="http://www.foo.com/bar.png" alt="URL not found"></body></html>
klcjr89
  • 5,862
  • 10
  • 58
  • 91
-1

I found the answer in this post: UIWebView loadHTMLString shows blank screen As I suspected it wasn't a Worklight problem at all. Returning YES in shouldStartLoadWithRequest rather than doing nothing did the trick. Odd how it works in some deployment scenarios and not others.

Community
  • 1
  • 1
Jonathan Sweetman
  • 605
  • 1
  • 6
  • 16