Skip to content

preStartGame:completion: ​

Pre-start Game (by Game ID) ​

This method asynchronously starts the game's pre-start flow via the game's unique identifier (Game ID). It not only covers resource checking and runtime environment loading (preLoad), but also further triggers the initialization execution of the game logic. This interface allows the game to complete first-frame rendering preparation in advance in the background, achieving an almost imperceptible instant switch when the user actually triggers the "Start" command.


Method Declaration ​

objectivec
/**
 Pre-start game using game ID. 
 Initializes the environment and executes initial game logic in the background.
 @param gameID The unique identifier of the game.
 @param completion Called when the pre-start operation finishes.
 @return An instance of id<SUDOPGameTask> to track the pre-start task.
 */
+ (id<SUDOPGameTask>)preStartGame:(NSString *)gameID
                       completion:(nullable SUDOPGameOperationCompletion)completion;

Parameters ​

ParameterTypeRequiredDescription
gameIDNSString *YesThe unique identifier of the game.
completionSUDOPGameOperationCompletionNoCallback invoked after the asynchronous pre-start finishes. On success, gameHandleProvider provides the pre-warmed game handle.

Return Value ​

Returns an object conforming to the id<SUDOPGameTask> protocol, used to manage this pre-start task (such as monitoring the status or executing cancel to release pre-warmed resources).


Runtime Behavior ​

  1. Automatic Chain Conversion: The SDK automatically checks whether the resource for this gameID exists locally. If not, it internally attempts to obtain the signature and trigger the download flow.
  2. Background Silent Running: The game engine starts and executes scripts, but at this point no visible view (View) is created, and audio output is not enabled by default.
  3. State Readiness: When the game completes the network requests and resource decoding required for the first frame, the completion callback is triggered.

Example Code ​

objectivec
// Suitable to call when the user taps into the game detail page, to pre-warm in advance
[SUDOP preStartGameWithGameID:@"game_101" completion:nil];

Notes ​

  • Resource Consumption: Compared with preLoad, preStart consumes more CPU and memory because it involves the actual running of the game scripts.
  • Cancellation Mechanism: If the user leaves the relevant page without starting the game, it is recommended to call [preStartTask cancel] to stop the background-running game logic and release resources.
  • Subsequent Calls: Once this interface succeeds, a subsequent startGame call for the same gameID will directly use this pre-warmed instance, achieving an extremely fast response.