Ver código fonte

城市列表接口

hjx 1 ano atrás
pai
commit
d11f3b5da2

+ 4 - 0
TOKTOK/TOKTOK.xcodeproj/project.pbxproj

@@ -132,6 +132,7 @@
 		84B9184829F23C61003CF0A0 /* XSTTBlindBoxDetailsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B9184729F23C61003CF0A0 /* XSTTBlindBoxDetailsViewController.m */; };
 		84B9184B29F27579003CF0A0 /* XSTTBlindBoxDetailsGoodsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B9184A29F27579003CF0A0 /* XSTTBlindBoxDetailsGoodsTableViewController.m */; };
 		84B9184E29F28858003CF0A0 /* XSTTBlindBoxDetailsTipsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B9184D29F28858003CF0A0 /* XSTTBlindBoxDetailsTipsViewController.m */; };
+		84CADD132A1CA7F1004B0600 /* t_xstt_city_data.db in Resources */ = {isa = PBXBuildFile; fileRef = 84CADD122A1CA7F1004B0600 /* t_xstt_city_data.db */; };
 		84CD5AF929F7719E00531BB6 /* AppDelegate+XSTTPushNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CD5AF829F7719E00531BB6 /* AppDelegate+XSTTPushNotification.m */; };
 		84CD5AFD2A04E7BE00531BB6 /* XSTTBeerDetailsRadarMapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CD5AFC2A04E7BE00531BB6 /* XSTTBeerDetailsRadarMapView.m */; };
 		84D3FCDD268C45DE00D61979 /* UIControl+XSTTButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 84D3FCDC268C45DE00D61979 /* UIControl+XSTTButton.m */; };
@@ -413,6 +414,7 @@
 		84B9184A29F27579003CF0A0 /* XSTTBlindBoxDetailsGoodsTableViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XSTTBlindBoxDetailsGoodsTableViewController.m; sourceTree = "<group>"; };
 		84B9184C29F28858003CF0A0 /* XSTTBlindBoxDetailsTipsViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XSTTBlindBoxDetailsTipsViewController.h; sourceTree = "<group>"; };
 		84B9184D29F28858003CF0A0 /* XSTTBlindBoxDetailsTipsViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XSTTBlindBoxDetailsTipsViewController.m; sourceTree = "<group>"; };
+		84CADD122A1CA7F1004B0600 /* t_xstt_city_data.db */ = {isa = PBXFileReference; lastKnownFileType = file; path = t_xstt_city_data.db; sourceTree = "<group>"; };
 		84CD5AF729F7719E00531BB6 /* AppDelegate+XSTTPushNotification.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AppDelegate+XSTTPushNotification.h"; sourceTree = "<group>"; };
 		84CD5AF829F7719E00531BB6 /* AppDelegate+XSTTPushNotification.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "AppDelegate+XSTTPushNotification.m"; sourceTree = "<group>"; };
 		84CD5AFB2A04E7BE00531BB6 /* XSTTBeerDetailsRadarMapView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XSTTBeerDetailsRadarMapView.h; sourceTree = "<group>"; };
@@ -584,6 +586,7 @@
 		840B9E8728F2C3850032B0D2 /* DB */ = {
 			isa = PBXGroup;
 			children = (
+				84CADD122A1CA7F1004B0600 /* t_xstt_city_data.db */,
 				840B9E8828F2C38E0032B0D2 /* t_xstt_location_cache_data.db */,
 			);
 			path = DB;
@@ -1450,6 +1453,7 @@
 				847C879026944CFB00BEBD03 /* Mine.xcassets in Resources */,
 				8439FEFD292CAABD00DF0533 /* XSTTtoktokLaunchScreen.storyboard in Resources */,
 				84287A7129DEA7570037FD51 /* AlipayNumber-Regular.ttf in Resources */,
+				84CADD132A1CA7F1004B0600 /* t_xstt_city_data.db in Resources */,
 				849C707928C33E7500BE760C /* SocialCircle.xcassets in Resources */,
 				849C709228C5D5DF00BE760C /* SF-Pro-Text-MediumItalic.otf in Resources */,
 				840D74702A0B8FB200938D3A /* loading.json in Resources */,

+ 1 - 0
TOKTOK/TOKTOK/Public/Model/XSTTAppProfileModel.h

@@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, readonly, strong) NSString *xstt_updatable;
 @property (nonatomic, readonly, strong) NSString *xstt_forceUpdate;
 @property (nonatomic, readonly, strong) NSString *xstt_versionName;
+@property (nonatomic, readonly, strong) NSString *xstt_districtVersion;
 
 @end
 

+ 2 - 0
TOKTOK/TOKTOK/Public/Profile/XSTTKeyProfile.h

@@ -19,6 +19,8 @@ CONST_STRING_INTERFACE XSTTBaseJudgeVersionKey;
 
 CONST_STRING_INTERFACE XSTTPersonalPrivacy;//隐私框
 
+CONST_STRING_INTERFACE XSTTCityRefreshTime;
+
 //keychain
 CONST_STRING_INTERFACE XSTTLoginStatusKeychainServiece;
 CONST_STRING_INTERFACE XSTTLoginStatusTokenKeychainAccount;

+ 3 - 1
TOKTOK/TOKTOK/Public/Profile/XSTTKeyProfile.m

@@ -16,7 +16,9 @@ CONST_STRING XSTTAPPEnterBackgroundTimeKey = @"XSTTAPPEnterBackgroundTimeKey";
 
 CONST_STRING XSTTBaseJudgeVersionKey = @"XSTTBaseJudgeVersionKey";
 
-CONST_STRING XSTTPersonalPrivacy = @"SPPersonalPrivacy";//隐私框
+CONST_STRING XSTTPersonalPrivacy = @"XSTTPersonalPrivacy";//隐私框
+
+CONST_STRING XSTTCityRefreshTime = @"XSTTCityRefreshTime";
 
 //keychain
 CONST_STRING XSTTLoginStatusKeychainServiece = @"XSTTLoginStatusKeychainServiece";

+ 1 - 0
TOKTOK/TOKTOK/Public/Profile/XSTTSQLProfile.h

@@ -11,5 +11,6 @@
 #import <JXHMacro.h>
 
 CONST_STRING_INTERFACE XSTTLocationCacheDataSQL;
+CONST_STRING_INTERFACE XSTTCityCacheDataSQL;
 
 CONST_STRING_INTERFACE XSTTLocationCachePersonalInformationSQLKey;

+ 1 - 0
TOKTOK/TOKTOK/Public/Profile/XSTTSQLProfile.m

@@ -11,5 +11,6 @@
 
 
 CONST_STRING XSTTLocationCacheDataSQL = @"t_xstt_location_cache_data.db";
+CONST_STRING XSTTCityCacheDataSQL = @"t_xstt_city_data.db";
 
 CONST_STRING XSTTLocationCachePersonalInformationSQLKey = @"XSTTLocationCachePersonalInformationSQLKey";

+ 1 - 0
TOKTOK/TOKTOK/Public/Profile/XSTTURLApiProfile.h

@@ -21,6 +21,7 @@ NSURL *xstt_fileURL(NSString *url);
 
 #pragma mark - APP状态相关
 CONST_STRING_INTERFACE XSTTUrlGetVersion;
+CONST_STRING_INTERFACE XSTTUrlGetCity;
 
 #pragma mark - 短信
 CONST_STRING_INTERFACE XSTTURLGetSms;

+ 1 - 0
TOKTOK/TOKTOK/Public/Profile/XSTTURLApiProfile.m

@@ -57,6 +57,7 @@ NSURL *xstt_fileURL(NSString *url) {
 
 #pragma mark - APP状态相关
 CONST_STRING XSTTUrlGetVersion = @"/sys/version/last/version";
+CONST_STRING XSTTUrlGetCity = @"/district/list";
 
 #pragma mark - 短信
 CONST_STRING XSTTURLGetSms = @"/account/login/sms/send/v1";

BIN
TOKTOK/TOKTOK/Resource/DB/t_xstt_city_data.db


+ 59 - 1
TOKTOK/TOKTOK/TOKTOK/AppDelegate+XSTTHandleData.m

@@ -15,6 +15,9 @@
 #import "XSTTNetworkManager.h"
 #import "XSTTAppProfileModel.h"
 #import "XSTTConstantProfile.h"
+#import <JXHSystemShortcut.h>
+#import <objc/runtime.h>
+#import <JXHFMDBManager.h>
 
 @implementation AppDelegate (XSTTHandleData)
 
@@ -22,7 +25,7 @@
     NSString *orginaPath;
     NSString *targetPath;
     NSFileManager *fileManager = [NSFileManager defaultManager];;
-    NSArray *tableNameArray = @[@"t_xstt_location_cache_data"];
+    NSArray *tableNameArray = @[@"t_xstt_location_cache_data", @"t_xstt_city_data"];
     for (NSInteger i = 0; i < tableNameArray.count; i ++) {
         orginaPath = [[NSBundle mainBundle] pathForResource:tableNameArray[i] ofType:@"db"];
         targetPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.db", tableNameArray[i]]];
@@ -59,9 +62,55 @@
         } else if (update) {
             
         }
+        if (![jxh_userDefaults() objectForKey:XSTTCityRefreshTime] || [[jxh_userDefaults() objectForKey:XSTTCityRefreshTime] integerValue] != model.xstt_districtVersion.integerValue) {
+            self.tempCityRefreshTime = model.xstt_districtVersion;
+            [self getCityList];
+            
+        }
     }];
 }
 
+#pragma mark - 获取城市列表
+- (void)getCityList {
+    @weakify(self)
+    [xstt_globalNetworkManager() networkUseMethod:XSTTNetworkMethodGET isLogin:false signKey:XSTTNetworkSignKeyApp url:xstt_appUrl(XSTTUrlGetCity) urlParameters:nil parameters:nil completion:^(NSError * _Nonnull error, id  _Nullable data) {
+        if (error.code == XSTTNetworkCallbackSuccessCode && [data[@"data"][@"provinceList"] isKindOfClass:[NSArray class]] && [data[@"data"][@"cityList"] isKindOfClass:[NSArray class]] && [data[@"data"][@"districtList"] isKindOfClass:[NSArray class]]) {
+            @strongify(self)
+            [self handleCityWithData:data[@"data"]];
+        }
+    }];
+}
+
+- (void)handleCityWithData:(NSDictionary *)data {
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        NSString *provinceStr = [self appendSqlStrWithArray:data[@"provinceList"] tableName:@"t_xstt_city_province"];
+        NSString *cityStr = [self appendSqlStrWithArray:data[@"cityList"] tableName:@"t_xstt_city_city"];
+        NSString *districtStr = [self appendSqlStrWithArray:data[@"districtList"] tableName:@"t_xstt_city_district"];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [JXHFMDBManager updateWithPath:XSTTCityCacheDataSQL condition:^id(FMDatabase *database) {
+                return @([database executeUpdate:@"delete from t_xstt_city_province"] && [database executeUpdate:@"delete from t_xstt_city_city"] && [database executeUpdate:@"delete from t_xstt_city_district"]);
+            }];
+            [JXHFMDBManager updateWithPath:XSTTCityCacheDataSQL condition:^id(FMDatabase *database) {
+                return @([database executeUpdate:provinceStr] && [database executeUpdate:cityStr] && [database executeUpdate:districtStr]);
+            }];
+            [jxh_userDefaults() setObject:self.tempCityRefreshTime forKey:XSTTCityRefreshTime];
+            [jxh_userDefaults() synchronize];
+        });
+    });
+}
+
+- (NSString *)appendSqlStrWithArray:(NSArray *)array tableName:(NSString *)tableName {
+    NSMutableString *sqlStr = [NSMutableString stringWithFormat:@"insert into %@ (id, pid, name) values", tableName];
+    for (NSInteger i = 0; i < array.count; i ++) {
+        [sqlStr appendFormat:@"('%@', '%@', '%@'),", array[i][@"districtId"], array[i][@"pid"], array[i][@"districtName"]];
+        if (i == array.count - 1) {
+            [sqlStr replaceCharactersInRange:NSMakeRange(sqlStr.length - 1, 1) withString:@""];
+        }
+    }
+    return sqlStr;
+}
+
+
 - (void)loadCache {
     XSTTPersonalInformationModel *personalInformationModel = [XSTTCacheManager getPersonalInformationCache];
     if (!personalInformationModel) {
@@ -72,4 +121,13 @@
 //    xstt_setAccountWallet(XSTTAccountWalletModel.new);
 }
 
+- (void)setTempCityRefreshTime:(NSString *)tempCityRefreshTime {
+    objc_setAssociatedObject(self, _cmd, tempCityRefreshTime, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+- (NSString *)tempCityRefreshTime {
+    NSString *object = objc_getAssociatedObject(self, @selector(setTempCityRefreshTime:));
+    return object;
+}
+
 @end

+ 1 - 0
TOKTOK/TOKTOK/TOKTOK/AppDelegate.m

@@ -32,6 +32,7 @@
 
 
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+    debugLog(@"%@", NSHomeDirectory());
     [self clearCacheOfLaunchScreenIfNeeded];
     if (@available(iOS 15.0, *)) {
         [UITableView appearance].sectionHeaderTopPadding = 0;