1
This commit is contained in:
@@ -42,6 +42,72 @@
|
||||
if (completion) completion(user, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fetchCharacterListByUserWithCompletion:(KBCharacterListCompletion)completion{
|
||||
[[KBNetworkManager shared] GET:KB_API_CHARACTER_LISTBYUSER
|
||||
parameters:nil
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary *jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
[KBHUD dismiss];
|
||||
|
||||
if (error) {
|
||||
NSString *msg = KBBizMessageFromJSONObject(jsonOrData) ?: error.localizedDescription ?: KBLocalized(@"Network error");
|
||||
[KBHUD showInfo:msg];
|
||||
if (completion) completion([NSArray new], error);
|
||||
return;
|
||||
}
|
||||
|
||||
id dataObj = jsonOrData[KBData] ?: jsonOrData[@"data"];
|
||||
if (![dataObj isKindOfClass:[NSArray class]]) {
|
||||
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
|
||||
code:KBNetworkErrorInvalidResponse
|
||||
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid response")}];
|
||||
[KBHUD showInfo:e.localizedDescription];
|
||||
if (completion) completion([NSArray new], e);
|
||||
return;
|
||||
}
|
||||
NSArray<KBCharacter *> *list = [KBCharacter mj_objectArrayWithKeyValuesArray:(NSArray *)dataObj];
|
||||
if (completion) completion(list, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
/// 上传头像
|
||||
- (void)upLoadAvatarWithData:(NSData *)avatarData completion:(KBUpLoadAvatarCompletion)completion{
|
||||
[KBHUD show];
|
||||
[[KBNetworkManager shared] uploadFile:KB_API_FILE_UPLOAD
|
||||
fileData:avatarData
|
||||
fileName:@"avatar.jpg"
|
||||
mimeType:@"image/jpeg"
|
||||
headers:nil
|
||||
completion:^(NSDictionary * _Nullable json,
|
||||
NSURLResponse * _Nullable response,
|
||||
NSError * _Nullable error) {
|
||||
[KBHUD dismiss];
|
||||
if (error) {
|
||||
NSLog(@"上传失败: %@", error);
|
||||
return;
|
||||
}
|
||||
NSString *avImageString = json[@"data"];
|
||||
// [weakSelf.avatarView kb_setImageURL:[NSURL URLWithString:avImageString] placeholder:KBPlaceholderImage];
|
||||
|
||||
NSLog(@"上传成功: %@", json);
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
/// 更新用户信息
|
||||
- (void)updateUserInfo:(KBUser *)user completion:(KBUpdateUserInfoCompletion)completion{
|
||||
/// 获取用户信息
|
||||
KBUser *localUser = [KBUserSessionManager shared].currentUser;
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
if (localUser.userId.length) params[@"uid"] = localUser.userId;
|
||||
if (localUser.nickName.length) params[@"nickName"] = localUser.nickName;
|
||||
params[@"gender"] = (NSInteger)localUser.gender;
|
||||
if (localUser.avatarUrl.length) params[@"avatarUrl"] = localUser.avatarUrl;
|
||||
|
||||
}
|
||||
|
||||
- (void)logout{
|
||||
[KBHUD show];
|
||||
[[KBNetworkManager shared] GET:API_LOGOUT
|
||||
|
||||
Reference in New Issue
Block a user