chenqiyang
2021-09-01 fe877009c7d5b5f8e4a49e8bfdf8033aa444d86e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
//  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