getGameListWithOptions:completion:
获取游戏列表
getGameListWithOptions 方法用于分页获取游戏列表,通过回调返回分页信息和当前页的游戏数据。
按选品单查询游戏,请使用 getGameListWithSelectionId:options:completion:。两个方法对应不同的服务端接口,原方法保持不变。
按品类查询请使用 getGameListWithCategoryOptions:completion:,品类编码通过 getCategoryListWithOptions:completion: 获取。
调用前置条件
调用该方法前,必须先调用 initializeWithConfiguration:completion: 并确保 SDK 初始化成功。
方法声明
objectivec
+ (void)getGameListWithOptions:(nullable SUDOPGameListOptions *)options
completion:(nullable void(^)(SUDOPGameListResult *_Nullable result,
NSError *_Nullable error))completion;参数说明
| 参数名 | 类型 | 必传 | 描述 |
|---|---|---|---|
| options | SUDOPGameListOptions * | 否 | 分页和语言参数。传入 nil 时使用第 0 页、每页 10 条及服务端默认语言。 |
| completion | Block | 否 | 请求完成后的回调。成功时返回 result;失败时返回 error。回调在主线程执行。 |
SUDOPGameListOptions
| 字段 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| pageNo | NSInteger | 0 | 页码,从 0 开始。小于 0 时按 0 处理。 |
| pageSize | NSInteger | 10 | 每页条数。小于或等于 0 时按 10 处理。 |
| language | NSString * | nil | 语言标识,例如 zh-CN。nil 或空字符串使用服务端默认值,SDK 不自动替换为系统语言。 |
返回模型 SUDOPGameListResult
| 字段 | 类型 | 描述 |
|---|---|---|
| pageNo | NSInteger | 服务端返回的当前页码,从 0 开始。 |
| pageSize | NSInteger | 服务端返回的每页条数。 |
| total | NSInteger | 游戏总数。 |
| records | NSArray<SUDOPGameListItem *> * | 当前页的游戏列表。 |
SUDOPGameListItem
| 字段 | 类型 | 描述 |
|---|---|---|
| gameId | NSString * | 游戏 ID。 |
| gameName | NSDictionary<NSString *, NSString *> * | 游戏名(多语言),key 为语言标签,value 为对应语言的游戏名。 |
| gameIcon | NSString * | 默认游戏图标 URL。 |
| icon | NSDictionary<NSString *, NSString *> * | 多语言图标 URL 字典,key 为语言标签,default 表示默认图标;响应缺失该字段时可为 nil。 |
| version | NSString * | 游戏版本号。 |
| gameIntroduction | NSDictionary<NSString *, NSString *> * | 多语言游戏简介,key 为语言标签;响应缺失时可为 nil。 |
| categoryInfo | SUDOPCategoryListItem * | 游戏分类信息,包含分类编码、多语言名称、父分类编码和层级;响应缺失时可为 nil。 |
代码示例
objectivec
SUDOPGameListOptions *options = [[SUDOPGameListOptions alloc] init];
options.pageNo = 0;
options.pageSize = 20;
options.language = @"zh-CN";
[SUDOP getGameListWithOptions:options
completion:^(SUDOPGameListResult * _Nullable result,
NSError * _Nullable error) {
if (error) {
NSLog(@"获取游戏列表失败: %@", error.localizedDescription);
return;
}
NSLog(@"当前页: %ld,总数: %ld", (long)result.pageNo, (long)result.total);
for (SUDOPGameListItem *item in result.records) {
NSLog(@"游戏 ID: %@,版本: %@", item.gameId, item.version);
}
}];注意事项
- 页码从 0 开始。
- 该方法会发起网络请求,请通过
completion异步处理结果。 - 翻页时建议以返回结果中的
pageNo、pageSize和total判断是否还有下一页。 - 返回
error时,请检查网络状态和控制台中的游戏配置。
