How to load localized html file from WKWebView?

Viewed 2213

1st StackOverflow question for me...

!! Objective-C !!

I'm in the process of updating an old app and am working on help screens. I chose to display some useful How-tos through some html mainly for the ease of formatting the text (bullet points, colors, bold, underline etc...). Since the app is a bit complex, The help screens are in a total of 3: A main info webpage that links to 2 other detailed pages.

Tha app is localized in English (Base) and French.

Once the setup was complete, and with everything working fine, I went ahead and localized the base html files.

Now, they are neatly placed in the Base.lproj and fr.lproj files.

But when when I tap on a link to another page from the main WebView, nothing happens !

Any ideas ?

Thanks

Here are some bits of code I'm using: In the .h file :

@interface howToViewController : UIViewController <WKUIDelegate>  
{  
    WKWebView *infoText;  
    NSString *uRLString;  
}  
@property (nonatomic, retain) WKWebView *infoText;

In the .m file: (had to programmatically create the WKWebView because of the known Xcode 9 bug when creating it through Storyboards)

- (void)viewDidLoad  
{  
    [super viewDidLoad];  
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
WKWebView *aWebView = [[WKWebView alloc] initWithFrame:self.view.frame  
                                         configuration:theConfiguration];  
aWebView.UIDelegate = self;  
self.infoText = aWebView;  

NSURL *url = [[NSBundle mainBundle] URLForResource:@"infoHTML" withExtension:@"html"];  
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];  
NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];  

[infoText loadHTMLString:html baseURL:baseUrl];  

[self.view addSubview:infoText];  
}  

In the html file, the links that no longer work once the files are localized:

<p>3/ More information is available for the respective tabs by pressing the following links :</p>  
    <ul><li><a href="pageOne.html">Limitations</a>  
    </li></ul>  
    <ul><li><a href="pageTwo.html">Fueling</a>  
    </li></ul>  
1 Answers

Working code from one of my apps. I'm using NSURLRequest and WKWebView's loadRequest instance method. I'm not sure what's going wrong with your use of loadHTMLString:baseURL: but I think it may have something to do with the value you're passing for the baseURL argument. Have you cleared the console, then single-stepped over that line of code to see if you're getting any message in the console?

NSURL *url = [[NSBundle mainBundle] URLForResource: pageString withExtension: @"html"]; 
NSURLRequest *request = [NSURLRequest requestWithURL: url];
[webView loadRequest: request];
Related