If a miniapp fails to load because of a network issue or an inaccessible website, an error message appears, such as "Network connection failed (-1009)".
This topic describes how to customize the error page.
Procedure
You can customize the error page in two steps:
In the H5 base class, add a listener for the
kEvent_Navigation_Errormethod. Implement the- (void)handleEvent:(PSDEvent *)eventmethod in yourMPH5WebViewController () <PSDPluginProtocol>class extension:- (void)handleEvent:(PSDEvent *)event { [super handleEvent:event]; if ([kEvent_Navigation_Error isEqualToString:event.eventType]) { [self handleContentViewDidFailLoad:(id)event]; } }The
handleContentViewDidFailLoadmethod is as follows:- (void)handleContentViewDidFailLoad:(PSDNavigationEvent *)event { PSDNavigationEvent *naviEvent = (PSDNavigationEvent *)event; NSError *error = naviEvent.error; [MPH5ErrorHelper handlErrorWithWebView:(WKWebView *)self.psdContentView error:error]; }In the
- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptionsmethod ofDTFrameworkInterface, you can set theerrorpage and the H5 base class. TheerrorHtmlPathparameter specifies the path to the HTML error page that is displayed when an H5 page fails to load. By default, the system reads theMPNebulaAdapter.bundle/error.htmlfile.
The code for
myerroris 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>