4. Start to use Griver AppContainer
To open a mini program or a web app, refer to the code below. Make sure Griver AppContainer is initialized beforehand.
Open a mini program
The openAppWithApppId API is called by the super app to open mini programs with appId, the unique ID of the mini program.
Method signature
func openApp(withApppId appId: String, extraParams: [String: Any]?, error: ()) throws -> UIViewController?
Request parameters
Name | Type | Description | Required |
appId | String | The unique ID that is assigned by Mini Program Platform to identify a mini program. You can get the ID from the Mini Program Platform console or by fetching mini program information with the fetchApps API. | M |
extraParams | [String: Any]? | This parameter is used to pass startup parameters to IAPMini Program SDK to customize the behavior of a mini program during startup. See Startup parameters for details. | O |
Response parameters
N/A
Error codes
Error code | Error message | Description | Further action |
90002 | GRV_CONTAINER_NOT_INITIALIZED | IAPMiniProgram SDK is not initialized. | Initialize the SDK. |
90003 | GRV_CONTAINER_ERROR_UNKNOWN | Parameter error. | Refer to the Request parameters table and check if all parameter types are correct and if all required parameters are specified. |
Sample
do {
let appId = "xxx"
let extraParams = ["query": "a=b&c=d"]
let viewController = try GRVAppContainerLaunch.sharedInstance().openApp(withApppId: appId, extraParams: extraParams, error: ())
} catch {
}
Open a web app
The openAppWithUrl API is called by the super app to open mini programs with urlStr, the URL of the mini program.
Method signature
func openApp(withUrl urlStr: String, extraParams: [String: Any]?, error: ()) throws -> UIViewController?
Request parameters
Name | Type | Description | Required |
urlStr | String | The scheme URL of the mini program. The URL should use the HTTP or HTTPs protocols and include the _ariver_appid, _ariver_path, and _ariver_version query string parameters. | M |
extraParams | [String: Any]? | This parameter is used to pass startup parameters to IAPMini Program SDK to customize the behavior of a mini program during startup. See Startup parameters for details. | O |
Response parameters
N/A
Error codes
Error code | Error message | Description | Further action |
90002 | GRV_CONTAINER_NOT_INITIALIZED | IAPMiniProgram SDK is not initialized. | Initialize the SDK. |
90003 | GRV_CONTAINER_ERROR_UNKNOWN | Parameter error. | Refer to the Request parameters table and check if all parameter types are correct and if all required parameters are specified. |
Sample
do {
let url = "xxx"
let extraParams = ["query": "a=b&c=d"]
let viewController = try GRVAppContainerLaunch.sharedInstance().openApp(withApppId: url, extraParams: extraParams, error: ())
} catch {
}
Preview and remote debug mini program
The Mini Program Studio provides the ability to preview and remote debug a mini program. To scan the QR code that is generated by Mini Program Studio and then preview or remote debug the mini program, your app should follow these steps to achieve scanability.
Step 1: Scan the QR code
First of all, your app should have a scanner. Use your scanner to scan the QR code that Mini Program Studio generated, and get the scan results.
Step 2: Recognize the mini program QR code
As your scanner is a universal scanner, it may get different scan results. So you need to recognize the result of scanning the mini program QR code.
The result of scanning the mini program QR code has the following rules.
• It is a text that can parse to a valid URI.
• It must have the _ariver_appid
, _ariver_path
, and _ariver_version
query string.
Take the following QR code scanning result as an example:
mini://platformapi/startapp?_ariver_appid=2171010045421679&_ariver_path=&_ariver_version=0.1.1587126785630&_ariver_source=debug&_ariver_scene=PREVIEW&_ariver_token=ee3fa2b45c414b91ac090cb1fd04eda6
[GRVAppContainerLaunch openAppWithUrl:extraParams:]
if the URL is a valid URI that includes the _ariver_appid
. So when you find that the scanning result meets the rules mentioned above, treat it as a mini program QR code.Step 3: Open by Griver AppContainer
After you recognize the scanning result is a mini program QR code, pass the scan result to Griver AppContainer directly by calling [GRVAppContainerLaunch openAppWithUrl:extraParams:]
. Then you can use your app to preview or remote debug the mini program in Mini Program Studio.
Multi-environment support
Griver AppContainer provides multi-environment support. If you set GRVConfiguration's environment parameter when the application started, you can only get a mini program published in this environment. To publish a mini program in the production environment, do not set the environment parameter. Here is an example:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// init AC
let configuration = GRVConfiguration()
configuration.environment = "dev"
}
Now Griver AppContainer supports the following environments:
dev
: The development environmenttest
: The test environmentsandbox
: The sandbox environment
Note: If you do not set the environment parameter, it means you can get a mini program published in the production environment.