You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.1 KiB

//
// TFSystemInfoManager.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/3.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFSystemInfoManager.h"
#import "TFAreaCodeModel.h"
@implementation TFSystemInfoManager
static NSString *_taskReadProductionId = nil;
+ (void)setTaskReadProductionId:(NSString *)taskReadProductionId
{
if (!taskReadProductionId) return;
_taskReadProductionId = taskReadProductionId;
[self.systemDict setObject:taskReadProductionId forKey:KEY_PATH(self, taskReadProductionId)];
[self.systemDict writeToFile:self.systemPath atomically:YES];
}
+ (NSString *)taskReadProductionId
{
return _taskReadProductionId ?: [self.systemDict objectForKey:@"taskReadProductionId"]?:@"";
}
static NSString *_masterUnit = nil;
+ (void)setMasterUnit:(NSString *)masterUnit
{
if (!masterUnit) return;
_masterUnit = masterUnit;
[self.systemDict setObject:masterUnit forKey:KEY_PATH(self, masterUnit)];
[self.systemDict writeToFile:self.systemPath atomically:YES];
}
+ (NSString *)masterUnit
{
return _masterUnit ?: [self.systemDict objectForKey:@"masterUnit"] ?: Main_Unit_Name;
}
static NSString *_subUnit = nil;
+ (void)setSubUnit:(NSString *)subUnit
{
if (!subUnit) return;
_subUnit = subUnit;
[self.systemDict setObject:subUnit forKey:KEY_PATH(self, subUnit)];
[self.systemDict writeToFile:self.systemPath atomically:YES];
}
+ (NSString *)subUnit
{
return _subUnit ?: [self.systemDict objectForKey:@"subUnit"] ?: Sub_Unit_Name;
}
static NSInteger _sexChannel = 0;
+ (void)setSexChannel:(NSInteger)sexChannel
{
_sexChannel = sexChannel;
[self.systemDict setObject:[NSString stringWithFormat:@"%zd", sexChannel] forKey:KEY_PATH(self, sexChannel)];
[self.systemDict writeToFile:self.systemPath atomically:YES];
}
+ (NSInteger)sexChannel
{
return _sexChannel ?: [[self.systemDict objectForKey:@"sexChannel"] integerValue] ?: 1;
}
static NSString *_magicStatus = nil;
+ (void)setMagicStatus:(NSString *)magicStatus
{
_magicStatus = magicStatus;
[self.systemDict setObject:magicStatus forKey:KEY_PATH(self, magicStatus)];
[self.systemDict writeToFile:self.systemPath atomically:YES];
}
+ (NSString *)magicStatus
{
return _magicStatus ?: [self.systemDict objectForKey:@"magicStatus"];
}
static BOOL _isAgree = NO;
+ (void)setIsAgree:(BOOL)isAgree
{
_isAgree = isAgree;
[self.systemDict setObject:[NSString stringWithFormat:@"%d", isAgree] forKey:KEY_PATH(self, isAgree)];
[self.systemDict writeToFile:self.systemPath atomically:YES];
}
+ (BOOL)isAgree
{
return _isAgree ?: [[self.systemDict objectForKey:@"isAgree"] boolValue];
}
static NSString *_firstGenderSelecte = nil;
+ (void)setFirstGenderSelecte:(NSString *)firstGenderSelecte
{
_firstGenderSelecte = firstGenderSelecte;
[self.systemDict setValue:firstGenderSelecte forKey:KEY_PATH(self, firstGenderSelecte)];
[self.systemDict writeToFile:self.systemPath atomically:YES];
}
+ (NSString *)firstGenderSelecte
{
return _firstGenderSelecte ?: [self.systemDict objectForKey:@"firstGenderSelecte"];
}
static NSString *_zoneNumber = nil;
+ (void)setZoneNumber:(NSString *)zoneNumber
{
_zoneNumber = zoneNumber;
[self.systemDict setValue:zoneNumber forKey:KEY_PATH(self, zoneNumber)];
[self.systemDict writeToFile:self.systemPath atomically:YES];
}
+ (NSString *)zoneNumber
{
if (!_zoneNumber) {/**< 从本地记录获取*/
_zoneNumber = [self.systemDict objectForKey:@"zoneNumber"];
if (!_zoneNumber) {/**< 从当前语言环境和时区获取*/
NSString *path = [[NSBundle mainBundle] pathForResource:@"areaCode.json" ofType:nil];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
TFAreaCodeModel *t_model = [TFAreaCodeModel modelWithJSON:data];
NSString *zoneCode = [[NSLocale currentLocale] objectForKey:NSLocaleIdentifier];
for (TFAreaCodeListModel *list in t_model.list) {
for (TFAreaCodeDetailModel *obj in list.list) {
if ([zoneCode hasSuffix:obj.code]) {
TFSystemInfoManager.zoneNumber = obj.areaCode;
return _zoneNumber;
}
}
}
TFSystemInfoManager.zoneNumber = @"86";
}
}
return _zoneNumber;
}
static NSMutableDictionary *_systemDict = nil;
+ (NSMutableDictionary *)systemDict
{
if (!_systemDict) {
_systemDict = [NSMutableDictionary dictionaryWithContentsOfFile:self.systemPath];
if (!_systemDict) {
_systemDict = [NSMutableDictionary dictionary];
}
}
return _systemDict;
}
+ (NSString *)systemPath
{
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:[System_Info_Path stringByAppendingPathExtension:@"plist"]];
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
}
return path;
}
@end