All Products
Search
Document Center

FAQ of using HTML5 in iOS

Last Updated: Mar 24, 2021

Preset offline packages do not take effect when using the file H5_json.json.

A: In baseline 10.1.32, only .plist files are supported. In baseline 10.1.60, both .plist and .json files are supported.

How to obtain information on applications installed with offline packages?

A: Refer to this code: NSDictionary *installedApps = [NAMServiceGet() installApps:nil];.

How to force update of all offline packages’ information?

A: You may use the encapsulated method requestAllNebulaApps to perform a full update.

  1. [[MPNebulaAdapterInterface shareInstance]requestAllNebulaApps:^(NSDictionary *data, NSError *error) {
  2. }];

In iOS 13, the component vux-ui pulldown may hang during a scrolling operation in the H5 container.

A: This problem occurs because a bug of UIWebview is triggered in the iOS operating system. You may consider switching to WKWebview or changing the front-end components. To learn how to switch to WKWebview, see mPaaS 10.1.60 adapts WKWebView.

How to view all JSAPIs and plug-ins registered by the current application?

A: Open an H5 page, enter the Xcode View hierarchy page, and use po [[PSDService sharedInstance] jsApis] in the lldb console to view all JSAPIs . Similarly, use po [[PSDService sharedInstance] plugins] to view all registered plug-ins.

1

How to obtain UIViewController and Webview objects of current H5 page in a JSAPI or plug-in?

A: During the actual execution, in a plug-in you can directly obtain the parameter event.context, in a JSAPI you can obtain context, in the context object PSDContext you can obtain all information or references you want, for example, reference to the current controller event.currentViewController and reference to the current WebView context.currentViewController.psdContentView.

2

3

How to obtain startup parameters passed from front end upon loading of current page?

A: Directly obtain attribute of the current VC psdScene.createParam.expandParams.

4

How to allow a JSAPI work within a certain offline package only?

A: Within the actual execution method of JSAPI, obtain appId of the offline package for the current page and then decide whether to execute the logic.

5

How to block page URL?

A: You can implement this by customizing a plug-in and then monitoring the related event.

  • Monitored event name:
  1. [PSDProxy addEventListener:kEvent_Proxy_Request_Start_Handler withListener:self useCapture:YES];
  2. `
  • Implement the blocking:
  1. else if ([kEvent_Proxy_Request_Start_Handler isEqualToString:event.eventType]
  2. && [event isKindOfClass:[PSDProxyEvent class]] ){
  3. NSLog(@"-----kNBEvent_Scene_NavigationItem_Right_Setting_Click----");
  4. PSDProxyEvent *proxyEvent = (PSDProxyEvent*) event;
  5. NSMutableURLRequest *redirectReq = proxyEvent.request.mutableCopy;
  6. NSString *appId = event.context.currentSession.createParam.expandParams[@"appId"];
  7. NAMApp *app = [NAMServiceGet() findApp:appId version:nil];
  8. NSString *fallBackUrl = app.fallback_host;
  9. NSString *vhost = app.vhost;;
  10. NSString *url = redirectReq.URL.absoluteString;
  11. NSLog(@"url__%@______fallBackUrl:%@",url,fallBackUrl);
  12. if ([url containsString:@"www.baidu.com"]) {
  13. [proxyEvent preventDefault];
  14. }}

How to manually invoke JSAPI in Native?

A: You can directly invoke the callHandler method of the base class for the current page. See the following source code for an example.

6

After the console releases new version of offline packages, the client cannot successfully load the new offline packages.

A: Before viewing the solution to this problem, make sure you already understand How are offline packages updated. If the client cannot successfully load the new packages, rendering of offline packages can generate errors at any stage. We can troubleshoot this problem using the following steps.

  • View the result returned by the RPC for fully updating offline packages. In the console, search for bizType: 4 Double-check details of the returned offline package and confirm that the latest package information was obtained from the console.
    7

  • If you found no problem in the previous step, then check if the offline packages in the sandbox directory were successfully decompressed. Note: If the current offline package references contents in the global resource package, then the decompressed directory must also contain the global resource package.
    8

  • If you did not find the corresponding offline packages in the sandbox directory in the previous step, you can temporarily turn off signature verification of offline packages, delete the app and run again. If the loading returns to normal after you turn off signature verification, it suggests that the private key used to create signatures for the offline packages are inconsistent with the public key used to verify signatures in the client. To resolve this problem, you need to update the corresponding public key information in the client.

  • If you found no problem in all the previous steps and this problem persists, you can use Safari to debug the corresponding H5 page and view actual cause of the errors. Examples of the causes include incorrect path of global resource package and invalid URL for loading the offline packages.
    9

Why is it that I see a blank page or the 400 error code when opening H5 page of an offline package?

A: Usual cause of the blank page or 400 error code is: The local offline package fails to load and thus the online fallback address is used. But because fallback address of the corresponding page does not exist, the page fails to load.

  • Find out why the client fails to load offline packages using the steps in the previous topic.
  • Regarding the problem of failing to load the online fallback address, ensure correct version of the corresponding offline package was generated and already uploaded using the console, including normal offline package and global resource package. For more details, see Generate offline packages.
  • If a preset offline package has an invalid online fallback address, first ensure the same preset offline package was also uploaded using the console.
    10
  • Ensure fallback_base_url in the local preset package information fallback_base_url and fallback_base_url in the configuration file h5_json.json downloaded from the console fallback_base_url are the same.
    11 12
  • And fallback_base_url + main_url the combined address “fallback_base_url + main_url” can be loaded normally in a web browser.
    13

How to disable the swipe gesture for returning to previous page in an H5 page?

A: You may disable this gesture in a front-end H5 page or in the base class of a native H5 container.

  • Disable the gesture in a front-end H5 page: Invoke setGestureBack JSAPI to implement this. Use this method when you need to disable the swipe gesture for returning to the previous page in a certain H5 page.
  1. AlipayJSBridge.call('setGestureBack',{val:false});
  • Disable the gesture in the base class of a native H5 container: In the method viewDidAppear of the base class, invoke API of the system for disabling this gesture and set the parameter guestBack. Use this method when you need to disable the swipe gesture for returning to the previous page in multiple or all H5 pages.

    1. - (void)viewDidAppear:(BOOL)animated {
    2. [super viewDidAppear:animated];
    3. self.options.gestureBack = NO;
    4. if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    5. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    6. }
    7. }

How to judge whether the current page is a page within a mini program?

A: Obtain session of the current page, and invoke isTinyAppWithSession isTinyAppWithSession to judge this. The code sample is as follows:

  1. PSDSession *session = self.psdSession;
  2. BOOL isTinyApp = [NBUtils isTinyAppWithSession:session];

How does an H5 page pass custom parameters?

A: Based on the ways to pass parameters, the following scenarios exist:

  • Native H5: When invoking the method startH5ViewControllerWithParams , pass [[MPNebulaAdapterInterface shareInstance] startH5ViewControllerWithParams:@{@"url": @"https://tech.antfin.com", @"key1":@"value1"}];.
  • Native - offline package: When invoking the method startH5ViewControllerWithNebulaApp , pass [[MPNebulaAdapterInterface shareInstance] startH5ViewControllerWithNebulaApp:@{@"appId":@"70000000",@"param":@{@"key2":@"value2"}}];.
  • H5 - H5: When invoking pushWindow put the custom parameters in passData :
  1. AlipayJSBridge.call('pushWindow', {
  2. // URL of the page to be opened
  3. url: 'https://m.taobao.com/',
  4. // Configuration parameters of the opened page
  5. param: {
  6. readTitle: true, // Automatically read title
  7. showOptionMenu: false, // Hide menu on the right
  8. transparentTitle:'always',
  9. },
  10. // Optional, used for transferring parameters to a newly opened page.
  11. // Use AlipayJSBridge.startupParams to obtain passData on a newly opened page.
  12. passData: {
  13. key1: "key1Value",
  14. key2: "key2Value"
  15. }
  16. });
  • H5 - offline package: When invoking startApp jsapi, put the custom parameters in param:
  1. AlipayJSBridge.call('startApp', {
  2. appId: '70000000',
  3. param: {
  4. key1:'value1'
  5. }
  6. }, function(result) {
  7. // noop
  8. });

How to obtain parameters passed from an H5 page?

A: You can obtain them either from the front end or Native:

  • Obtain from front end: Obtain using the method startupParams.
  1. // Startup parameters of the current page.
  2. AlipayJSBridge.startupParams
  • Obtain from Native: Obtain using the VC object for the current page.
  1. // Startup parameters of the current page.
  2. NSDictionary *expandParams = self.psdScene.createParam.expandParams;
  3. NSLog(@"[mpaas] expandParams: %@", expandParams);

How to block JsApi invocation?

A: You can implement this by customizing a plug-in and then monitoring the related event.

  • Monitored event name:kEvent_Invocation_Event_Start.
  • Perform the blocking: Obtain information including the name and passed parameters of JSAPI.
  1. else if([kEvent_Invocation_Event_Start isEqualToString:event.eventType]) {
  2. PSDInvocationEvent * invocationEvent = (PSDInvocationEvent *)event;
  3. NSString * apiName = invocationEvent.invocationName;
  4. if([apiName isEqualToString:@"setOptionMenu"] || [apiName isEqualToString:@"showOptionMenu"] ) {
  5. NSLog(@"wwww");
  6. }
  7. }