All Products
Search
Document Center

Mobile Platform as a Service:iOS FAQ

Last Updated:Mar 04, 2024

This article introduces common problems and corresponding solutions during the process of integrating to iOS.

Note:

  • To facilitate unified processing, we recommend that you specify the base class of all HTML5 pages and WebViews during initialization of the HTML5 container.

    a1

  • When the frontend is developing an offline package, make sure that Chinese characters are not contained in the paths and file names. Otherwise, the client fails to decompress the offline package.

  • The absolute length of each resource path in offline packages must not exceed 100 characters. Otherwise, the client fails to decompress .tar packages and the pages are blank.

How to solve the problem of H5 container positioning offset

Answer: You may encounter the problem of H5 container positioning offset when using mPaaS containers. Please refer to the following methods to update the settings:

- (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    //Skip LBS targeting
    [LBSmPaaSAdaptor sharedInstance].shouldSkipLBSLocation = YES;

    .......
    
}

Why does the offline package file named H5_json.json not take effect?

Answer: Baseline 10.1.32 supports only the PList format. Baseline 10.1.60 supports both the PList and JSON formats.

How do I obtain the app information of an installed offline package?

Answer: Execute the code defined based on the following sample code: NSDictionary *installedApps = [NAMServiceGet() installApps:nil];.

How do I force update the information about all offline packages?

Answer: Use the packaged requestAllNebulaApps method to perform a full update.

[[MPNebulaAdapterInterface shareInstance]requestAllNebulaApps:^(NSDictionary *data, NSError *error) {

 }];

In iOS 13, why is the tvux-ui pulldown component freezes in the HTML5 container during swiping?

Answer: This problem is resulted from the bug of UIWebview in iOS. You can use WKWebview instead of the component or change the frontend component. For more information about how to use WKWebview instead of the component, see Adapt mPaaS 10.1.60 to WKWebView.

How do I check all JSAPI operations and plug-ins that are registered in the current app?

Answer: Open an HTML5 page. Go to a view-layer page in Xcode. In the lldb console, run po [[PSDService sharedInstance] jsApis] to view all registered JSAPI operations. Similarly, run po [[PSDService sharedInstance] plugins] to view all registered plug-ins.1

How do I obtain the UIViewController and WebView objects of the current HTML5 page in the JSAPI or plug-in?

Answer: During execution, the plug-in can directly obtain the event.context parameter and the JSAPI operation can obtain the context parameter. In the PSDContext object, you can obtain all the information or references that you want. Such references include the references to the current event.currentViewController controller and the referenced context.currentViewController.psdContentView of the current WebView.23

How do I obtain the WebView of the current HTML5 page?

Answer: The WebView of the current HTML5 page is an attribute of the current ViewController. You can obtain the WebView by using vc.psdContentView. In the JSAPI or plug-in, the ViewController of the current page can be obtained by using the preceding method.

Note

When you want to obtain the WebView of the current page in the base class of HTML5 pages, use the viewWillAppear method. The WebView parameter is not created in the viewDidLoad method. If you use this method, the returned value is nil.

image.png

How do I obtain the startup parameters passed in by the frontend when the current page is loaded?

Answer: Obtain the psdScene.createParam.expandParams attribute of the current ViewController.

image.png

How do I limit JSAPI to taking effect only for a specified offline package?

Answer: In the execution method of JSAPI, obtain the appId of the offline package to which the current page belongs and determine whether to execute the logic.5

How do I intercept a page URL?

Answer: You can customize the plug-in to listen to events.

  • Listen to specified events:[PSDProxy addEventListener:kEvent_Proxy_Request_Start_Handler withListener:self useCapture:YES];.

  • Intercept and process the events.

else if ([kEvent_Proxy_Request_Start_Handler isEqualToString:event.eventType]
        && [event isKindOfClass:[PSDProxyEvent class]] ){

        NSLog(@"-----kNBEvent_Scene_NavigationItem_Right_Setting_Click----");
        PSDProxyEvent *proxyEvent = (PSDProxyEvent*) event;
        NSMutableURLRequest *redirectReq = proxyEvent.request.mutableCopy;
        NSString *appId = event.context.currentSession.createParam.expandParams[@"appId"];

        NAMApp *app = [NAMServiceGet() findApp:appId version:nil];
        NSString *fallBackUrl = app.fallback_host;
        NSString *vhost = app.vhost;;
        NSString *url = redirectReq.URL.absoluteString;


       NSLog(@"url__%@______fallBackUrl:%@",url,fallBackUrl);
       if ([url containsString:@"www.baidu.com"]) {
           [proxyEvent preventDefault];

 }}

How do I intercept the URL of the current page before the current HTML5 page is loaded?

Answer: In the base class of HTML5 pages, in the proxy method that implements the lifecycle of UIWebView, listen to the kEvent_Navigation_Start event, intercept it before the page is loaded, and obtain the WebView and URL of the current page to perform processing.

image.png

How do I manually call a JSAPI operation in Native?

Answer: Sometimes, on the Native side, you may need to manually call a specified JSAPI operation on the current page. This can be achieved by calling the operation of the current ViewController shown in the following figure.

image.png

Why does a local preset offline package fail to be loaded?

Answer: The failure in loading a preset resource package is generally caused by the mismatching between the preset package version and the package information. Before you test the local preset offline package, close the network connection to prevent the offline package from being updated. This ensures that version that is locally preset is loaded.

Check whether the information about the locally preset offline package is consistent with the package information configured in the PList file. Such information includes the appID, version, and main_url.c11

On the client, why do I fail to load a package with a new version that is released in the console?

Answer: Before you view the solution to this problem, ensure that you have understood How to update an offline package. If the client cannot load a new package, errors may occur in all rendering phases of the offline package. The following code shows how to locate the error.

  1. Check the response of the RPC to fully update the offline package. In the console, search for “bizType: 4” to view the details of the returned offline package. Make sure that the latest package information released in the console is pulled.

  2. View the offline package information in the finish callback method for loading the offline package. Make sure that the offline package is the latest package released by the console, and the error parameter is set to nil. Make sure that the appID, version, and main_url of the offline package are correct.

  3. Check whether the offline package is decompressed in the sandbox directory. If the current offline package references the content of the global resource package, the global resource package must also exist in the directory.c3

  4. If the offline package does not exist in the sandbox directory in the previous step, you can temporarily disable signature verification for the offline package, delete the app, and run the client again. If loading is normal after signature verification is disabled, the private key of the offline package that is used for signature is inconsistent with the public key of the client that is used for verification. Update the public key information of the client.c4

  5. After all the preceding steps, if the offline package still fails to be updated, you can use Safari to debug the HTML5 page to locate the cause for the error. For example, check whether the path to the global resource package is correct and whether the URL for loading the offline package exists.c5

Why does a global resource package fail to be loaded?

Answer: If the debugging results on Safari show that the global resource package fails to be loaded, you can perform the following steps to troubleshoot:

  1. Verify that the global resource package is registered.

  2. Check whether the offline package is decompressed in the sandbox directory.c13

  3. Check whether the path to the referenced global resource package is valid. Ensure that no Chinese characters exist in the reference path.

Why does a white screen or a 400 error occurs after the HTML5 page of an offline package is opened?

Answer: A white screen or a 400 error is generally caused by the failure in loading a local offline package. When the failure occurs, the online fallback address is used, while the fallback address of the corresponding page does not exist.As a result, the HTML5 page fails to be loaded. Perform the following steps to troubleshoot:

  1. Locate the cause for the loading failure of the offline package on the client based on the preceding troubleshooting steps for offline packages.

  2. If the online fallback address fails to be loaded, verify that the offline package with the specified version is generated and both the common offline package and the global resource package are uploaded in the console. For more information, see Generating an offline package.

  3. If the online fallback address fails to be loaded for the preset offline package, make sure that the preset offline package is also uploaded in the console.

  4. Make sure that the fallback_base_url parameter in the information about the local preset package is consistent with the fallback_base_url parameter in the configuration file h5_json.json that is downloaded in the console.1112

  5. In addition, verify that the spliced address specified by fallback_base_url + main_url can be loaded in browsers.

    image.png

How do I disable the Swipe Back gesture on HTML5 pages?

Answer: You can disable the gesture on a frontend HTML5 page and the base class of the native HTML5 container.

  1. Disable the gesture on a frontend HTML5 page: Call the setGestureBack JSAPI. This method is applicable to the scenario where you want to disable the Swipe Back gesture on a specified page.AlipayJSBridge.call('setGestureBack',{val:false});.

  2. Disable the gesture on the base class of the native HTML5 container: In the viewDidAppear method of the base class, call the system API operation for disabling the Swipe Back gesture. In addition, set the guestBack parameter. This method is applicable to scenarios where you want to disable the Swipe Back gesture on multiple or all HTML5 pages.

    - (void)viewDidAppear:(BOOL)animated {
         [super viewDidAppear:animated];
    
         self.options.gestureBack = NO;
         if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
             self.navigationController.interactivePopGestureRecognizer.enabled = NO;
         }
     }

How do I check whether the current page is a Mini Program page?

Answer: Obtain the session where the current page is located and then call the isTinyAppWithSession operation to check whether the current page is a Mini Program page. The following sample code is for your reference.

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

How do I pass custom parameters on an HTML5 page?

Answer: The methods for passing custom parameters vary depending on scenarios.

  • Native - HTML5 page: Call the startH5ViewControllerWithParams method to pass the following parameters:[[MPNebulaAdapterInterface shareInstance] startH5ViewControllerWithParams:@{@"url": @"https://tech.antfin.com", @"key1":@"value1"}];.

  • Native - offline package: Call the startH5ViewControllerWithNebulaApp method to pass the following parameters:[[MPNebulaAdapterInterface shareInstance] startH5ViewControllerWithNebulaApp:@{@"appId":@"70000000",@"param":@{@"key2":@"value2"}}];.

  • HTML5 page - HTML5 page: Call the pushWindow operation with the custom parameter specified in passData.

    AlipayJSBridge.call('pushWindow', {
    // URL of the page to be opened.
    url: 'https://m.taobao.com/',
    // Configuration parameters of the opened page
    param: {
      readTitle: true, // Automatically reads the title.
      showOptionMenu: false, // Hides the right-side menu.
    transparentTitle:'always',
    },
    // Optional, used for transferring parameters to a newly opened page.
    // Use AlipayJSBridge.startupParams to obtain passData on a newly opened page.
    passData: {
      key1: "key1Value",
      key2: "key2Value"
    }
    });
  • HTML5 page - offline package: Call the JSAPI operation startApp with the custom parameter specified in the param parameter.

    AlipayJSBridge.call('startApp', {
    appId: '70000000',
    param: {
    key1:'value1'
    }
    }, function(result) {
    // noop
    });

How do I obtain a passed parameter from an HTML5 page?

Answer: The methods vary depending on scenarios.

  • Obtain the passed parameter from the frontend: Call the startupParams method.

    // The startup parameters of the current page.
    AlipayJSBridge.startupParams
  • Obtain the passed parameter from the native component: Obtain the passed parameter from the ViewController object where the current page is located.

    // The startup parameters of the current page.
    NSDictionary *expandParams = self.psdScene.createParam.expandParams;
    NSLog(@"[mpaas] expandParams: %@", expandParams);

How do I intercept a JSAPI call?

Answer: You can customize the plug-in to listen to events.

  • Listen to the event specified by using kEvent_Invocation_Event_Start.

  • Intercept and process the event. Obtain the name of the JSAPI operation and the passed parameters.

    else if([kEvent_Invocation_Event_Start isEqualToString:event.eventType]) {
          PSDInvocationEvent * invocationEvent = (PSDInvocationEvent *)event;
          NSString * apiName = invocationEvent.invocationName;
          if([apiName isEqualToString:@"setOptionMenu"] || [apiName isEqualToString:@"showOptionMenu"] ) {
              NSLog(@"wwww");
          }
      }