3
This commit is contained in:
@@ -10,6 +10,6 @@
|
||||
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (nonatomic, strong) UIWindow *window;
|
||||
|
||||
- (void)setupRootVC;
|
||||
@end
|
||||
|
||||
|
||||
@@ -92,20 +92,25 @@
|
||||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
self.window.backgroundColor = [UIColor whiteColor];
|
||||
[self.window makeKeyAndVisible];
|
||||
BaseTabBarController *vc = [[BaseTabBarController alloc] init];
|
||||
self.window.rootViewController = vc;
|
||||
|
||||
// 根据当前是否已登录决定入口:有 token 进主 TabBar,否则先进入登录页
|
||||
BOOL loggedIn = [[KBUserSessionManager shared] isLoggedIn];
|
||||
UIViewController *rootVC = nil;
|
||||
if (loggedIn) {
|
||||
rootVC = [[BaseTabBarController alloc] init];
|
||||
} else {
|
||||
rootVC = [[KBLoginVC alloc] init];
|
||||
}
|
||||
self.window.rootViewController = rootVC;
|
||||
}
|
||||
|
||||
/// 首次安装时,展示性别选择页作为根控制器
|
||||
- (void)setupSexSelectRootVC {
|
||||
KBLoginVC *vc = [[KBLoginVC alloc] init];
|
||||
KBSexSelVC *vc = [[KBSexSelVC alloc] init];
|
||||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
self.window.backgroundColor = [UIColor whiteColor];
|
||||
[self.window makeKeyAndVisible];
|
||||
self.window.rootViewController = vc;
|
||||
|
||||
return;
|
||||
|
||||
KBSexSelVC *sexVC = [KBSexSelVC new];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
sexVC.didFinishSelectBlock = ^{
|
||||
|
||||
@@ -70,7 +70,7 @@ typedef NS_ENUM(NSInteger, KBSexOption) {
|
||||
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[[KBNetworkManager shared] GET:KB_API_APP_CONFIG parameters:nil headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
[[KBNetworkManager shared] GET:@"https://www.apple.com.cn/" parameters:nil headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
NSLog(@"====");
|
||||
}];
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#import "KBLoginVC.h"
|
||||
#import <AuthenticationServices/AuthenticationServices.h>
|
||||
#import "KBLoginVM.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface KBLoginVC () <UITextViewDelegate>
|
||||
|
||||
@@ -155,11 +156,18 @@
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)onTapAppleLogin {
|
||||
// 后续可接入 Apple Sign-In 逻辑,这里先占位
|
||||
KBLOG(@"onTapAppleLogin");
|
||||
[[KBLoginVM shared] signInWithAppleFromViewController:KB_CURRENT_NAV completion:^(BOOL success, NSError * _Nullable error) {
|
||||
if (success) {
|
||||
[KBHUD showInfo:KBLocalized(@"Signed in successfully")];
|
||||
// 登录成功后切换到主 TabBar
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
id<UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;
|
||||
if ([appDelegate respondsToSelector:@selector(setupRootVC)]) {
|
||||
AppDelegate *delegate = (AppDelegate *)appDelegate;
|
||||
[delegate setupRootVC];
|
||||
}
|
||||
});
|
||||
} else {
|
||||
NSString *msg = error.localizedDescription ?: KBLocalized(@"Sign-in failed");
|
||||
[KBHUD showInfo:msg];
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#import "LSTPopView.h"
|
||||
#import "KBChangeNicknamePopView.h"
|
||||
#import "KBGenderPickerPopView.h"
|
||||
|
||||
#import "KBMyVM.h"
|
||||
@interface KBPersonInfoVC () <UITableViewDelegate, UITableViewDataSource, PHPickerViewControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>
|
||||
|
||||
// 列表
|
||||
@@ -37,6 +37,8 @@
|
||||
// 压缩后的头像 JPEG 数据(可用于上传)
|
||||
@property (nonatomic, strong) NSData *avatarJPEGData;
|
||||
|
||||
@property (nonatomic, strong) KBMyVM *myVM;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBPersonInfoVC
|
||||
@@ -185,7 +187,7 @@
|
||||
- (void)onTapAvatarEdit { [self presentImagePicker]; }
|
||||
|
||||
- (void)onTapLogout {
|
||||
[[KBUserSessionManager shared] logout];
|
||||
[self.myVM logout];
|
||||
}
|
||||
|
||||
#pragma mark - Lazy UI(懒加载)
|
||||
@@ -366,4 +368,11 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
- (KBMyVM *)myVM{
|
||||
if (!_myVM) {
|
||||
_myVM = [[KBMyVM alloc] init];
|
||||
}
|
||||
return _myVM;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
16
keyBoard/Class/Me/VM/KBMyVM.h
Normal file
16
keyBoard/Class/Me/VM/KBMyVM.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// KBMyVM.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/12/3.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBMyVM : NSObject
|
||||
- (void)logout;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
33
keyBoard/Class/Me/VM/KBMyVM.m
Normal file
33
keyBoard/Class/Me/VM/KBMyVM.m
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// KBMyVM.m
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/12/3.
|
||||
//
|
||||
|
||||
#import "KBMyVM.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@implementation KBMyVM
|
||||
- (void)logout{
|
||||
[KBHUD show];
|
||||
[[KBNetworkManager shared] GET:API_LOGOUT parameters:nil headers:nil completion:^(NSDictionary * jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
if (error != nil) {
|
||||
return;
|
||||
}
|
||||
NSString *message = jsonOrData[KBMessage];
|
||||
// if (code == KBBizCodeSuccess) {
|
||||
[KBHUD showSuccess:message];
|
||||
[[KBUserSessionManager shared] logout];
|
||||
// 登录成功后切换到主 TabBar
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
id<UIApplicationDelegate> appDelegate = UIApplication.sharedApplication.delegate;
|
||||
if ([appDelegate respondsToSelector:@selector(setupRootVC)]) {
|
||||
AppDelegate *delegate = (AppDelegate *)appDelegate;
|
||||
[delegate setupRootVC];
|
||||
}
|
||||
});
|
||||
// }
|
||||
}];
|
||||
}
|
||||
@end
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
|
||||
/// 项目
|
||||
#import "KBBizCode.h"
|
||||
#import "KBNetworkManager.h"
|
||||
#import "UIView+KBShadow.h"
|
||||
#import "UIImage+KBColor.h"
|
||||
|
||||
Reference in New Issue
Block a user