1
This commit is contained in:
@@ -236,6 +236,8 @@ typedef NS_ENUM(NSInteger, KBSexOption) {
|
||||
if (self.didFinishSelectBlock) {
|
||||
self.didFinishSelectBlock();
|
||||
}
|
||||
// 保存用户当前选择的性别,供后续登录接口使用
|
||||
[[NSUserDefaults standardUserDefaults] setInteger:self.selectedSex forKey:KBSexSelectedGenderKey];
|
||||
[[NSUserDefaults standardUserDefaults] setBool:true forKey:KBSexSelectShownKey];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
@@ -246,6 +248,8 @@ typedef NS_ENUM(NSInteger, KBSexOption) {
|
||||
if (self.didFinishSelectBlock) {
|
||||
self.didFinishSelectBlock();
|
||||
}
|
||||
// 保存用户当前选择的性别,供后续登录接口使用
|
||||
[[NSUserDefaults standardUserDefaults] setInteger:self.selectedSex forKey:KBSexSelectedGenderKey];
|
||||
[[NSUserDefaults standardUserDefaults] setBool:true forKey:KBSexSelectShownKey];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@
|
||||
if (identityToken.length) params[@"identityToken"] = identityToken;
|
||||
if (authorizationCode.length) params[@"accessCode"] = authorizationCode; // 仅供后端需要时使用
|
||||
if (cred.user.length) params[@"userID"] = cred.user; // 可选
|
||||
// 如有本地缓存的性别(首次进入首页时选择),一并上传给后端
|
||||
NSNumber *genderNumber = [self kb_localGenderParamIfAvailable];
|
||||
if (genderNumber != nil) {
|
||||
params[@"gender"] = genderNumber;
|
||||
}
|
||||
[KBHUD show];
|
||||
// 向服务端发起校验
|
||||
[[KBNetworkManager shared] POST:API_APPLE_LOGIN jsonBody:params headers:nil completion:^(NSDictionary * _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
@@ -77,6 +82,11 @@
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
if (email.length) params[@"email"] = email;
|
||||
if (password.length) params[@"password"] = password;
|
||||
// 如有本地缓存的性别(首次进入首页时选择),一并上传给后端
|
||||
NSNumber *genderNumber = [self kb_localGenderParamIfAvailable];
|
||||
if (genderNumber != nil) {
|
||||
params[@"gender"] = genderNumber;
|
||||
}
|
||||
// 向服务端发起校验
|
||||
[[KBNetworkManager shared] POST:API_EMAIL_LOGIN jsonBody:params headers:nil completion:^(NSDictionary * _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
[KBHUD dismiss];
|
||||
@@ -127,4 +137,21 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
/// 读取本地缓存的性别枚举值,用于登录接口上传到后端。
|
||||
/// - 用户在首次进入首页的性别选择页或个人资料页中选择后,会持久化到 NSUserDefaults。
|
||||
- (nullable NSNumber *)kb_localGenderParamIfAvailable {
|
||||
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
||||
// 只有在用户真正看过性别选择页后,才认为本地的性别有效
|
||||
BOOL hasShownSexVC = [ud boolForKey:KBSexSelectShownKey];
|
||||
if (!hasShownSexVC) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSInteger value = [ud integerForKey:KBSexSelectedGenderKey];
|
||||
if (value < UserSexMan || value > UserSexTwoSex) {
|
||||
return nil;
|
||||
}
|
||||
return @(value);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -177,6 +177,19 @@
|
||||
content.closeHandler = ^{ [weakPop dismiss]; };
|
||||
content.saveHandler = ^(NSDictionary *selected) {
|
||||
NSString *name = selected[@"name"] ?: @"";
|
||||
// 将选择结果同步到本地缓存,供后续登录接口使用
|
||||
NSString *genderId = selected[@"id"];
|
||||
NSInteger genderValue = 0;
|
||||
if ([genderId isKindOfClass:NSString.class]) {
|
||||
NSInteger v = [genderId integerValue];
|
||||
// 后端/模型使用 0/1/2,对应弹窗里的 1/2/3
|
||||
if (v >= 1 && v <= 3) {
|
||||
genderValue = v - 1;
|
||||
}
|
||||
}
|
||||
[[NSUserDefaults standardUserDefaults] setInteger:genderValue forKey:KBSexSelectedGenderKey];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
NSMutableArray *m = [weakSelf.items mutableCopy];
|
||||
NSMutableDictionary *d1 = [m[1] mutableCopy];
|
||||
d1[@"value"] = name; m[1] = d1; weakSelf.items = m;
|
||||
|
||||
@@ -66,8 +66,10 @@
|
||||
#define KB_UL_LOGIN KB_UL_BASE @"/login"
|
||||
#define KB_UL_SETTINGS KB_UL_BASE @"/settings"
|
||||
|
||||
/// 第一次安装
|
||||
/// 是否已经展示过性别选择页
|
||||
#define KBSexSelectShownKey @"kKBSexSelectShownKey"
|
||||
/// 本地存储的性别枚举值(UserSex / KBSexOption),0:Male 1:Female 2:The Third Gender
|
||||
#define KBSexSelectedGenderKey @"kKBSexSelectedGenderKey"
|
||||
|
||||
#define KBPlaceholderImage [UIImage imageNamed:@"placeholder_icon"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user