創造し続け、成長を加速!「ナゲッツデイリー新プラン・10月アップデートチャレンジ」参加6日目です、イベント詳細はこちら
前書き
パート 1 : 前提知識blog.csdn.net/u011018979/…パート 2: コアの実装 (アプリを開き、トークンの有効期限が切れていない場合は、最後にログインしたトークンを使用してインターフェイス リクエストを行います) blog.csdn.net/ u011018979/…
アプリ側のログアウト手順: blog.csdn.net/z929118967/…
Iコア実装
1.1 Session オブジェクトの作成
HSSingleton ツール クラスを使用してシングルトンを実装し、ログイン トークンおよびその他の状態関連フィールドを含む userInfo オブジェクトをシングルトン オブジェクトのプロパティとして使用します。
HSSingletonH(Session);
HSSingletonM(Session);
+ (void)SaveUserInfo:(UserInfoModel *)userInfo{
QCTSession.shareQCTSession.userInfo = userInfo;
}
复制代码
トークン情報を格納する
#pragma mark - ******** iOS 优化登录流程:【打开app,如果 token不过期,就使用最近一次登录的tokenn进行接口请求。】(现状是每次打开app都会重新登录)
+ (void)saveModelWithModel:(UserInfoModel*)userModel{
[self emptySeeionLocal];
userModel.bg_tableName = QCTUserInfoModelTableName;
BOOL isSave = [userModel bg_save];// 保存方法
if (isSave) {
NSLog(@"token保存成功:%@",userModel.mj_keyValues);
}else{
NSLog(@"token保存失败:%@",userModel.mj_keyValues);
}
}
+(void)emptySeeionLocal{
NSMutableArray *tmparr = [NSMutableArray arrayWithArray:[[self class] bg_find:QCTUserInfoModelTableName where:nil] ];
// 先删除
for (UserInfoModel *loginModel in tmparr) {
NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"bg_id"),bg_sqlValue(loginModel.bg_id)];
BOOL isDelete = [UserInfoModel bg_delete:[NSString stringWithFormat:@"%@",QCTUserInfoModelTableName] where:where];
NSLog(@"删除重复数据%@:%@",isDelete?@"成功":@"失败",loginModel.mj_keyValues);
// break;
//
}
}
复制代码
トークン情報を取得する
+ (instancetype)getmodel4LoginSeesion{
NSMutableArray *tmparr = [NSMutableArray arrayWithArray:[[self class] bg_find:QCTUserInfoModelTableName where:nil] ];
if(tmparr.count>0 ){
UserInfoModel *userModel = tmparr.firstObject;
// QCTSession.shareQCTSession.userInfo = userModel;
[ QCTSession SaveUserInfo:userModel];
NSLog(@"获取的token 信息%@",userModel);
return tmparr.firstObject;
}
NSLog(@"获取的token userModel.shareUserInfoModel %@",UserInfoModel.shareUserInfoModel);
//
return UserInfoModel.shareUserInfoModel;
}
复制代码
1.2 トークンを UserInfoModel オブジェクトに保存するタイミング
- ログイン時
[ Session SaveUserInfo:userModel];
[UserInfoModel saveModelWithModel:userModel];
复制代码
- アプリの終了時: applicationWillTerminate、applicationWillResignActive
- (void)applicationWillTerminate:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
[UserInfoModel saveModelWithModel:UserInfoModel.shareUserInfoModel];
}
复制代码
1.3 アプリを再度開いたときにトークンを取得する
#pragma mark - ******** 获取token信息
- (void)initInfo{
QCTSession.shareQCTSession.tmpUserInfoModel = nil;
[UserInfoModel getmodel4LoginSeesion];// 获取会话
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self initInfo];
}
复制代码
1.4 情報をクリアするためのログアウトまたは (トークン) 無効化
- アプリケーションで聞く :didFinishLaunchingWithOptions: メソッド
__weak __typeof__(self) weakSelf = self;
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:kExitlogshowLoginViewNotification object:nil] subscribeNext:^(NSNotification *notification) {
NSString *tmp = @"";
if(notification.object){
tmp = notification.object;
[weakSelf.window showHUDMessage:tmp afterBlock:^(id _Nonnull sender) {
[weakSelf setupExitlogout];
}];
}else{
// tmp = @"";
[weakSelf setupExitlogout];
}
}];
复制代码
- ログアウト(トークン期限切れ)処理
/**
1、移除极光的别名
2、初始化一些信息
3、清除账户信息缓存(本地数据库和内存中的token信息)
*/
- (void)setupExitlogout
{
[JPUSHService setTags:nil alias:@"" callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self];
[UserInfoModel cleanInfoWithblock:^(id sender) {
//3、登录
UserInfoModel.shareUserInfoModel.token = nil;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setupLoginV];
}];
}
复制代码
- ローカル データベースのトークンをクリアする
+ (void)cleanInfoWithblock:(void (^)(id sender))block{
[[UserInfoModel shareUserInfoModel] cleanInfo];
if(block){
block(nil);
}
}
- (void)cleanInfo{
#pragma mark - ******** 包括清除本地数据库的token
[[self class] emptySeeionLocal];//
[self setToken:nil];
_CurrentSysUser = nil;
// _
[QCTSession shareQCTSession].tmpUserInfoModel = nil;
}
复制代码
1.5 ログインインターフェースのviewDidLoadで直接ホームページに入るかどうかの判断
- viewDidLoad は、SubView の初期作成時に、ホームページに直接入るかどうかを判断します
if(UserInfoModel.shareUserInfoModel.isLoginByToken){
[[self class] jumpHome];
return;
}
复制代码
- トークンがあるかどうかを判断する
/**
判断是否有token
*/
- (BOOL)isLoginByToken{
if(![NSStringQCTtoll isBlankString:UserInfoModel.shareUserInfoModel.token]){
return YES;
}
return NO;
}
复制代码
II 実装に注意を払う
2.1 正式な環境とテスト環境を区別するトークン ストレージ
-
UserInfoModel オブジェクトは、現在のトークンのドメイン名プロパティ currentHost を追加します。これは、判定環境のクエリに使用されます。
-
BGFMDB に新しいフィールドを追加する場合は、テーブル名を変更する必要があります
#warning BGFMDB如果新增字段,就需要更换一下表名,否则在旧表会找不到字段,无法更新数据
2021-01-29 17:16:10.418453+0800 Housekeeper[15013:1071895] [logging] table QCTUserInfoModelTableName0401 has no column named BG_IsreqGetCurrentSysUsering in "insert into QCTUserInfoModelTableName0401(BG_currentHost,BG_BearerToken,BG_token,BG_DictionariesEnum,BG_DictionariesEnumDictionary,BG_loginCode,BG_isGotoChangePassword,BG_HaveDefaultLevel,BG_bg_updateTime,BG_loginMessage,BG_IsreqGetCurrentSysUsering,BG_IsTobacco,BG_bg_createTime,BG_MsgsourceStr,BG_isShowBindingMobileNote) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
复制代码
- ドメイン名に基づくアクセス トークン
NSString* where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"currentHost"),bg_sqlValue(currentHost)];
NSMutableArray *tmparr = [NSMutableArray arrayWithArray:[[self class] bg_find:QCTUserInfoModelTableName where:where] ];
复制代码
トークン情報を格納する
+ (void)saveModelWithModel:(UserInfoModel*)userModel{
[self emptySeeionLocal];
userModel.bg_tableName = QCTUserInfoModelTableName;
userModel.currentHost = currentHost;
BOOL isSave = [userModel bg_save];// 保存方法
if (isSave) {
NSLog(@"token保存成功:%@",userModel.mj_keyValues);
}else{
NSLog(@"token保存失败:%@",userModel.mj_keyValues);
}
}
复制代码
2.2 データストレージ
2020-03-30 19:23:12.877204+0800 Housekeeper[5577:1118700] DB Error: 1 "duplicate column name: BG_CompanyId"
BGFMDB は大文字と小文字をサポートしていないため、保存されたオブジェクトに大文字と小文字の 2 つのフィールドを含めることはできません。
@property (copy, nonatomic) NSString *companyId;
//@property (strong, nonatomic) NSString *CompanyId;
复制代码
2020-04-01 16:18:32.127564+0800 retail[8875:1402725] [logging] table QCTUserInfoModelTableName has no column named BG_currentHost
デバッグのヒント
新しいフィールドが BGFMDB のテーブルに追加された場合、テーブル名を変更して、フィールドが見つからず、データの更新に失敗することを回避できます。
新しいフィールドを追加する場合は、テーブル名を変更する必要があります
2.3 ログアウト時の関連データのクリーンアップ
// 3. 退出登录时清理消息推送的订单相关的打印数据
[ERPPrintInfo bg_clearAsync:QCTSNPrinterInfoTableName4push complete:^(BOOL isSuccess) {
}];
复制代码
III も参照
- シングル サインオン (シングル サインオン): SSO と呼ばれ、複数のアプリケーション システムで、ユーザーは 1 回ログインするだけで、相互に信頼されているすべてのアプリケーション システムにアクセスできます。
たとえば、Feishu アプリでサポートされている SSO
チームのスーパー管理者がこの機能を有効にし、管理バックグラウンドで構成を完了すると、チーム ユーザーはログイン時に SSO を選択し、企業ドメイン名を使用して Feishu に直接ログインできます。この機能は、個人ユーザーではなく、チーム ユーザーが利用できます。
- 新しく追加されたライブラリのみがインストールされ、更新されたライブラリは無視されます: blog.csdn.net/z929118967/…
➜ retail git:(develop) ✗ cat ~/bin/knpod
#!/bin/sh
#该命令只安装新添加的库,已更新的库忽略
pod install --verbose --no-repo-update
#该命令只更新指定的库,其它库忽略
#pod update 库名 --verbose --no-repo-update
exit 0% ➜ retail git:(develop) ✗
复制代码