setGameStartOptions:options:
Set game start options (multi-parameter version)
setGameStartOptions:options: is used to finely configure the mini game's runtime environment across multiple dimensions before it starts. This two-parameter declaration is typically used to distinguish basic start options from extended business configuration, or to distinguish engine configuration from user-defined data.
Method Declaration
objectivec
/**
* Set the game start options.
* @param gameOptions Configuration for the engine and framework level (such as entry path, debug mode).
* @param businessOptions Configuration for the business logic level (such as initial variables passed through to JS, channel info).
*/
- (void)setGameStartOptions:(NSDictionary *)gameOptions options:(NSDictionary *)businessOptions;Parameters
| Parameter | Type | Description |
|---|---|---|
| gameOptions | NSDictionary | Engine configuration: controls entryPath (entry), debug (debug switch), v8Flags, etc. |
| businessOptions | NSDictionary | Business configuration: injects envVars, userInfo, roomID, etc. for the game script to read directly. |
Runtime Behavior
- Parameter decoupling: Separates technical-level engine parameters from business-level logic parameters, facilitating modular management.
- Environment warm-up: Before calling
start:, these configurations are injected into the global context of the JavaScript Runtime. - Persistence strategy: This setting remains in effect while the current
gameHandleis active.
Example
objectivec
// 1. Define the engine-level configuration
NSDictionary *gameOpts = @{
@"entryPath": @"game.js",
@"debug": @(NO)
};
// 2. Define the business-level configuration
NSDictionary *bizOpts = @{
@"appId": @"sud123456",
@"subChannel": @"promotion_A",
@"launchData": @{@"referrer": @"group_chat"}
};
// 3. Apply the configuration
[self.gameHandle setGameStartOptions:gameOpts options:bizOpts];
// 4. Then start the game
[self.gameHandle start:@"{}"];Notes
- Strict timing: Must be called after
createand beforestart:. If called while the game is running, the parameters may not be captured by the JS script in theonLaunchlifecycle. - Null handling: If a part has no special configuration, you can usually pass an empty
@{}dictionary, but passingnilis not recommended unless the API documentation explicitly allows it. - Serialization consistency: The dictionary only supports JSON-compatible data types (string, number, boolean, array, dictionary); it does not support passing native
UIImageor custom object instances.
