onGetUserInfo:dataJson
Retrieve Basic User Info
This method is used to retrieve the original App user info. Its main purpose is to provide non-sensitive App user info to the game.
Method Declaration
objectivec
/**
* Triggered when the SDK requests basic user info (User Info).
* The App should return the user's basic info such as nickname and avatar via stateHandle in response to this request.
*
* @param stateHandle The state handle used to return the processing result to the SDK.
* @param dataJson A JSON string containing request parameters (such as a list of user IDs).
*/
- (void)onGetUserInfo:(id<SUDOPStateHandle>)stateHandle dataJson:(NSString*)dataJson;Runtime Behavior
- Trigger timing: This typically occurs when game initialization completes, a new player joins the room, or the user triggers "view someone's profile" in the game.
- Standard key definitions: The App must use the fields agreed upon in the SUDOP protocol (such as
nickname,avatar) to construct the returned JSON. - Asynchronous closed loop: Since user info may need to be fetched from the App Server, the App can sync data asynchronously via
[stateHandle success:]in the network request callback.
Code Example
Implement parsing, assembling, and returning of basic info:
objectivec
- (void)onGetUserInfo:(id<SUDOPStateHandle>)stateHandle dataJson:(NSString*)dataJson {
NSDictionary *result = @{
@"userId": uid,
@"nickname": [NSString stringWithFormat:@"iOS User_%@", uid],
@"avatar": @"https://cdn.example.com/avatars/default.png"
};
// 4. Convert the result to a JSON string and return it
NSData *resultData = [NSJSONSerialization dataWithJSONObject:result options:0 error:nil];
NSString *resultJson = [[NSString alloc] initWithData:resultData encoding:NSUTF8StringEncoding];
[stateHandle success:resultJson];
}Notes
- Avatar specification: It is recommended to provide a high-resolution avatar URL with a 1:1 aspect ratio, to ensure consistent display across game UIs of different sizes.
- Caching optimization: For frequently requested user info, it is recommended that the App establish a second-level cache, to avoid long-lasting placeholder images for in-game player avatars caused by network latency.
- Field rigor: Be sure to confirm that the returned JSON field names are consistent with the protocol definition (usually defined in the
SUDOPconstants class); otherwise the game engine may fail to recognize the data.
