When loading the mini program, if it fails to load the page or the website cannot be opened, an error similar to the following will appear.
"Network can't connect (-1009)"
This topic introduces how to customize the error in the above figure.
Procedure
Customizing the error page falls into the following 2 steps:
Listen to the
kEvent_Navigation_Errormethod in HTML5 base class.Introduce
- (void)handleEvent:(PSDEvent *)eventmethod viaMPH5WebViewController () <PSDPluginProtocol>interface:- (void)handleEvent:(PSDEvent *)event { [super handleEvent:event]; if ([kEvent_Navigation_Error isEqualToString:event.eventType]) { [self handleContentViewDidFailLoad:(id)event]; } }handleContentViewDidFailLoadmethod is as follows:- (void)handleContentViewDidFailLoad:(PSDNavigationEvent *)event { PSDNavigationEvent *naviEvent = (PSDNavigationEvent *)event; NSError *error = naviEvent.error; [MPH5ErrorHelper handlErrorWithWebView:(WKWebView *)self.psdContentView error:error]; }Set
errorpage and HTML5 base class inafterDidFinishLaunchingWithOptionsmethod.In which,
errorHtmlPathis the HTML error page path displayed when it fails to load the HTML5 page, and readsMPNebulaAdapter.bundle/error.htmlby default.The code of
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>