//
|
// configManager.m
|
// HDLLinPhoneSDK
|
//
|
// Created by 陈启扬 on 2021/8/12.
|
// Copyright © 2021 陈启扬. All rights reserved.
|
//
|
|
#import "configManager.h"
|
|
static configManager *theConfigManager;
|
@implementation configManager{
|
Config *config;
|
NSString *applicationKey;
|
}
|
+(instancetype)instance{
|
static configManager *service = nil;
|
static dispatch_once_t onceToken;
|
dispatch_once(&onceToken, ^{
|
service = [[configManager alloc] init];
|
// applicationKey=@"app";
|
});
|
return service;
|
}
|
-(instancetype)init{
|
self = [super init]; //用于初始化父类
|
if (self) {
|
applicationKey=@"app";
|
}
|
return self;
|
|
}
|
|
-(void)setDb:(LinphoneConfig*)cPointer{
|
config=[Config getSwiftObject:cPointer];
|
}
|
|
-(void)lpConfigSetString:(NSString *)value key:(NSString *)key section:(NSString *)section{
|
if (key!=nil) {
|
[config setString:section key:key value:value];
|
}
|
}
|
-(void)lpConfigSetString:(NSString *)value key:(NSString *)key{
|
[self lpConfigSetString:value key:key section:applicationKey];
|
}
|
-(NSString *)lpConfigStringForKey:(NSString *)key section:(NSString *)section defaultValue:(NSString *)defaultValue{
|
if (key==nil||!key) {
|
return defaultValue;
|
}
|
NSString *string=[config getString:section key:key defaultString:@""];
|
if (string!=nil) {
|
return string;
|
}
|
return defaultValue;
|
}
|
|
-(NSString *)lpConfigStringForKey:(NSString *)key section:(NSString *)section{
|
return [self lpConfigStringForKey:key section:section defaultValue:@""];
|
}
|
|
-(NSString *)lpConfigStringForKey:(NSString *)key defaultValue:(NSString *)defaultValue{
|
return [self lpConfigStringForKey:key section:applicationKey defaultValue:defaultValue];
|
}
|
-(NSString *)lpConfigStringForKey:(NSString *)key {
|
return [self lpConfigStringForKey:key defaultValue:@""];
|
}
|
|
-(void)lpConfigSetInt:(int)value key:(NSString *)key section:(NSString *)section{
|
if (key!=nil) {
|
[config setInt:section key:key value:value];
|
}
|
}
|
|
-(void)lpConfigSetInt:(int)value key:(NSString *)key {
|
[self lpConfigSetInt:value key:key section:applicationKey];
|
}
|
|
-(int)lpConfigIntForKey:(NSString *)key section:(NSString *)section defaultValue:(int)defaultValue {
|
if (key==nil) {
|
return defaultValue;
|
}
|
int val=[config getInt:section key:key defaultValue:defaultValue];
|
if (val) {
|
return val;
|
}
|
return defaultValue;
|
}
|
|
-(int)lpConfigIntForKey:(NSString *)key section:(NSString *)section {
|
return [self lpConfigIntForKey:key section:section defaultValue:-1 ];
|
}
|
|
-(int)lpConfigIntForKey:(NSString *)key defaultValue:(int)defaultValue {
|
return [self lpConfigIntForKey:key section:applicationKey defaultValue:defaultValue];
|
}
|
|
-(int)lpConfigIntForKey:(NSString *)key {
|
return [self lpConfigIntForKey:key defaultValue:-1];
|
}
|
|
-(void)lpConfigSetBool:(BOOL)value key:(NSString *)key section:(NSString *)section{
|
[self lpConfigSetInt:value?1:0 key:key section:section];
|
}
|
|
-(void)lpConfigSetBool:(BOOL)value key:(NSString *)key{
|
[self lpConfigSetBool:value key:key section:applicationKey];
|
}
|
|
|
//pragma mark - LPConfig Functions
|
|
-(BOOL)lpConfigBoolForKey:(NSString *)key section:(NSString *)section defaultValue:(BOOL)defaultValue{
|
if ( key==nil) {
|
return defaultValue;
|
}
|
int val=[self lpConfigIntForKey:key section:section defaultValue:-1];
|
return (val != -1) ? (val == 1) : defaultValue;
|
}
|
|
-(BOOL)lpConfigBoolForKey:(NSString *)key section:(NSString *)section {
|
return [self lpConfigBoolForKey:key section:section defaultValue:false];
|
}
|
|
-(BOOL)lpConfigBoolForKey:(NSString *)key defaultValue:(BOOL)defaultValue {
|
return [self lpConfigBoolForKey:key section:applicationKey defaultValue:defaultValue];
|
}
|
|
-(BOOL)lpConfigBoolForKey:(NSString *)key {
|
return [self lpConfigBoolForKey:key defaultValue:false];
|
}
|
|
@end
|