When loading the mini program, if it fails to load the page or the website cannot be opened, an error page similar to the following will appear:
This article introduces how to customize the error page in the above figure.
Procedure
Customizing the error page falls into the following 2 steps:
Listen to the
kEvent_Navigation_Error
method in HTML5 base class.
Introduce- (void)handleEvent:(PSDEvent *)event
method viaMPH5WebViewController () <PSDPluginProtocol>
interface:- (void)handleEvent:(PSDEvent *)event
{
[super handleEvent:event];
if ([kEvent_Navigation_Error isEqualToString:event.eventType]) {
[self handleContentViewDidFailLoad:(id)event];
}
}
handleContentViewDidFailLoad
method is as follows:- (void)handleContentViewDidFailLoad:(PSDNavigationEvent *)event
{
PSDNavigationEvent *naviEvent = (PSDNavigationEvent *)event;
NSError *error = naviEvent.error;
[MPH5ErrorHelper handlErrorWithWebView:(WKWebView *)self.psdContentView error:error];
}
- Set
error
page and HTML5 base class inafterDidFinishLaunchingWithOptions
method.
In which,errorHtmlPath
is the HTML error page path displayed when it fails to load the HTML5 page, and readsMPNebulaAdapter.bundle/error.html
by default.
The code ofmyerror
is as follows:
The result is as follows:<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
Custom error message
</body>
</html>