forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodePushConfig.m
99 lines (79 loc) · 2.8 KB
/
CodePushConfig.m
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
#import "CodePush.h"
#import <UIKit/UIKit.h>
@implementation CodePushConfig {
NSMutableDictionary *_configDictionary;
}
static CodePushConfig *_currentConfig;
static NSString * const AppVersionConfigKey = @"appVersion";
static NSString * const BuildVdersionConfigKey = @"buildVersion";
static NSString * const ClientUniqueIDConfigKey = @"clientUniqueId";
static NSString * const DeploymentKeyConfigKey = @"deploymentKey";
static NSString * const ServerURLConfigKey = @"serverUrl";
+ (instancetype)current
{
return _currentConfig;
}
+ (void)initialize
{
_currentConfig = [[CodePushConfig alloc] init];
}
- (instancetype)init
{
self = [super init];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSString *buildVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey];
NSString *deploymentKey = [infoDictionary objectForKey:@"CodePushDeploymentKey"];
NSString *serverURL = [infoDictionary objectForKey:@"CodePushServerURL"];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *clientUniqueId = [userDefaults stringForKey:ClientUniqueIDConfigKey];
if (clientUniqueId == nil) {
clientUniqueId = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[userDefaults setObject:clientUniqueId forKey:ClientUniqueIDConfigKey];
[userDefaults synchronize];
}
if (!serverURL) {
serverURL = @"https://codepush.azurewebsites.net/";
}
_configDictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
appVersion,AppVersionConfigKey,
buildVersion,BuildVdersionConfigKey,
serverURL,ServerURLConfigKey,
clientUniqueId,ClientUniqueIDConfigKey,
deploymentKey,DeploymentKeyConfigKey,
nil];
return self;
}
- (NSString *)appVersion
{
return [_configDictionary objectForKey:AppVersionConfigKey];
}
- (NSString *)buildVersion
{
return [_configDictionary objectForKey:BuildVdersionConfigKey];
}
- (NSDictionary *)configuration
{
return _configDictionary;
}
- (NSString *)deploymentKey
{
return [_configDictionary objectForKey:DeploymentKeyConfigKey];
}
- (NSString *)serverURL
{
return [_configDictionary objectForKey:ServerURLConfigKey];
}
- (NSString *)clientUniqueId
{
return [_configDictionary objectForKey:ClientUniqueIDConfigKey];
}
- (void)setDeploymentKey:(NSString *)deploymentKey
{
[_configDictionary setValue:deploymentKey forKey:DeploymentKeyConfigKey];
}
- (void)setServerURL:(NSString *)serverURL
{
[_configDictionary setValue:serverURL forKey:ServerURLConfigKey];
}
@end