getManagerWithName:options:
Get Feature Manager
getManagerWithName:options: is an instance method of the SUDRT protocol, used to obtain the engine's internal core subsystem managers. This method adopts the "service locator" pattern, allowing the host App to dynamically obtain the corresponding functional modules (such as the user center, plugin center, package management center, etc.) via specific constant keys, enabling on-demand invocation.
Method Declaration
objectivec
/**
* Gets a specific manager component.
* @param name A constant string that uniquely identifies the manager (see table below).
* @param options Additional configuration parameters when obtaining the manager (usually pass nil).
* @return The corresponding manager instance object, which must be cast to a concrete type per the documentation; returns nil if not supported.
*/
- (nullable NSObject *)getManagerWithName:(NSString *)name options:(nullable NSDictionary *)options;Common Manager Keys
The following core components can be obtained through this method:
| Constant Key | Corresponding Manager Function |
|---|---|
| SUDRT_KEY_MANAGER_USER | User Manager: Responsible for syncing App user information, handling login-state authentication, and multi-device account sync. |
| SUDRT_KEY_MANAGER_GAME_PACKAGE | Package Manager: Responsible for querying the list of installed games, obtaining package version information, and cleaning up specific game resources. |
| SUDRT_KEY_MANAGER_PLUGIN | Plugin Manager: Responsible for dynamically loading or unloading engine extension plugins. |
Runtime Behavior
- Singleton mapping: For the same
SUDRTinstance, the samenametypically returns the same singleton object, ensuring state consistency. - On-demand initialization: Some managers use a lazy-loading mechanism and are only initialized the first time this method is called to request them.
- Type casting: This method returns a generic
NSObject. Developers need to cast it to the corresponding protocol type (such asid<SUDRTUserManager>) based on the requested Key.
Code Example
The following is a typical usage of obtaining the user manager and injecting the currently logged-in user information:
objectivec
// 1. Get the user manager instance
id<SUDRTUserManager> userManager = (id<SUDRTUserManager>)[self.sdkInstance getManagerWithName:SUDRT_KEY_MANAGER_USER options:nil];
if (userManager) {
// 2. Inject the App-layer user information
NSDictionary *userInfo = @{
@"userId": @"user_9958",
@"nickname": @"CodeHunter",
@"avatar": @"https://example.com/a.jpg"
};
[userManager updateUserInfo:userInfo];
NSLog(@"[SUD] User manager configured successfully");
}Notes
- Non-null check: Since some lightweight or trimmed-down engines may not integrate specific modules, be sure to check whether the return value is
nilafter calling. - Options parameter: In most cases, passing
nilforoptionsis sufficient. Only in specific customization scenarios (such as a manager requiring multi-instance isolation) do you need to consult that manager's dedicated documentation to pass configuration. - Lifecycle: A manager's lifecycle is typically bound to the
SUDRTinstance. When the main engine instance is destroyed, these managers become invalid at the same time.
