AppDelegate.m
8.62 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "AppDelegate.h"
#import "xn_base_Client_AF.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <RCTSplashScreen/RCTSplashScreen.h>
#import "IQKeyboardManager.h"
#import <UMCommon/UMCommon.h> // 公共组件是所有友盟产品的基础组件,必选
#import <UMAnalytics/MobClick.h>
//#import <PgySDK/PgyManager.h>
//#import <PgyUpdate/PgyUpdateManager.h>
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapLocationKit/AMapLocationKit.h>
// 灰度模式处理使用,用于公祭日等场合
#import "UIColor+LhGray.h"
#import "UIImage+GrayImage.h"
#import "UIImageView+GrayImageview.h"
#import "UITabBarItem+LhGray.h"
#import "WKWebView+LhGray.h"
#define PATH_AT_Document(name) [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:name]
@implementation AppDelegate{
NSTimer *timer;
}
#pragma mark 创建单例
/**
* @author zsq
*
* @brief 创建单例
*
* @return self
*/
+ (instancetype)sharedInstance {
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// NSURL *jsCodeLocation;
//
// jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
if(!launchOptions)
{
[AppDelegate sharedInstance].isJump = NO;
}else{
[AppDelegate sharedInstance].isJump = YES;
}
NSFileManager *fileManager = [NSFileManager defaultManager];
// 获取文件路径 Documents
NSString *_settingPlistPath = PATH_AT_Document(@"tst.plist");
if(![fileManager fileExistsAtPath:_settingPlistPath]){
// 开始创建文件
[fileManager createFileAtPath:_settingPlistPath contents:nil attributes:nil];
// 默认写入
NSArray *defaultSetting = @[
@{@"key":@"enable_mourning_day",@"value":@"false",@"description":@"是否启用哀悼日模式,默认是false"}
];
[defaultSetting writeToFile:_settingPlistPath atomically:YES];
}
// 开启定时器查询
dispatch_async(dispatch_get_main_queue(), ^{
self->timer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(p_querySettings) userInfo:nil repeats:YES];
[self->timer fire];
});
// 判断缓存的设置配置
if([fileManager fileExistsAtPath:_settingPlistPath]){
NSArray *readArray = [NSArray arrayWithContentsOfFile:_settingPlistPath];
if(readArray && readArray.count > 0){
for(NSDictionary *dic in readArray) {
if(dic && dic.count > 0){
NSString *key = [dic objectForKey:@"key"];
NSString *value = [dic objectForKey:@"value"];
if([key isEqualToString:@"enable_mourning_day"]){
if([value isEqualToString:@"true"]){
//设置灰色模式
[UITabBarItem lh_tabbarItemSwizzldMethedWith:YES];
[UIColor lh_colorSwizzldColorMethedWith:YES];
[UIImage lh_imageSwizzldMethedWith:YES];
[UIImageView lh_imageViewSwizzldMethedWith:YES];
[WKWebView lh_WKWebViewWizzldMethedWith:YES];
}
}
}
}
}
}
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
#ifdef DEBUG
jsCodeLocation = [NSURL URLWithString:@"http://192.168.81.6:8081/index.ios.bundle?platform=ios&dev=true"];
// 钱鋆
jsCodeLocation = [NSURL URLWithString:@"http://192.168.5.171:8081/index.ios.bundle?platform=ios&dev=true"];
// jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.105:8081/index.ios.bundle?platform=ios&dev=true"];
#else
//release 模式
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
[UMConfigure initWithAppkey:@"5af105bfb27b0a5c8a00019e" channel:@"App Store"];
[MobClick setScenarioType:E_UM_NORMAL];
#endif
//启动基本SDK
// [[PgyManager sharedPgyManager] startManagerWithAppId:@"a8071f84ef516389d414860d8a62c387"];
// //启动更新检查SDK
// [[PgyUpdateManager sharedPgyManager] startManagerWithAppId:@"a8071f84ef516389d414860d8a62c387"];
// [[PgyUpdateManager sharedPgyManager] checkUpdate];
[[xn_base_Client_AF sharedInstance] f_configByUrl:@"https://railway-dt.shmetro.com/router" appKey:@"0617CA8376F9901F28FF46B69BF9CF44" appSecret:@"28570C9D069ED51226DD9F028BD5E6DD" maxTask:15];
//设置全局的键盘处理,不显示工具条
[[IQKeyboardManager sharedManager] setEnable:YES];
[[IQKeyboardManager sharedManager] setEnableAutoToolbar: NO];
[IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
[IQKeyboardManager sharedManager].shouldToolbarUsesTextFieldTintColor = YES;
[[AMapServices sharedServices] setEnableHTTPS:YES];
#ifdef test
[AMapServices sharedServices].apiKey =@"280cb15fd7417ef11542a0ea0e7e3395";
#else
[AMapServices sharedServices].apiKey =@"326a03ead349468ccbe3f4710864fd02";
#endif
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"metroApp"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[RCTSplashScreen show:rootView];
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application
{
dispatch_async(dispatch_get_main_queue(), ^{
[self->timer invalidate];
self->timer = nil;
});
}
#pragma mark - app之间通讯的唤起操作
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation
{
if ([[NSString stringWithFormat:@"%@",url] containsString:@"shpadtcomcn"]) {
NSString *str = [[NSString stringWithFormat:@"%@",url] substringFromIndex:[[NSString stringWithFormat:@"%@",url] rangeOfString:@"mobilePhone="].location+12];
NSString *strend = [str substringToIndex:[str rangeOfString:@"from="].location];
[AppDelegate sharedInstance].str_phone = strend;
}
return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
if ([[NSString stringWithFormat:@"%@",url] containsString:@"shpadtcomcn"]) {
NSString *str = [[NSString stringWithFormat:@"%@",url] substringFromIndex:[[NSString stringWithFormat:@"%@",url] rangeOfString:@"mobilePhone="].location+12];
NSString *strend = [str substringToIndex:[str rangeOfString:@"from="].location];
[AppDelegate sharedInstance].str_phone = strend;
}
return YES;
}
-(void)p_querySettings{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringCacheData];
//序列化
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
__block NSString *_settingPlistPath = PATH_AT_Document(@"tst.plist");
// 读取json配置信息
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); // 获得全局并发队列
dispatch_async(queue, ^{
@try{
// 测试地址
//https://xn-static.oss-cn-hangzhou.aliyuncs.com/soft/xntalk/xcarchive_backup/jscss/setting.json
// 生产地址
//@"https://padt-cdn.oss-cn-hangzhou.aliyuncs.com/soft/ditie/settings.json"
[manager GET:@"https://padt-cdn.oss-cn-hangzhou.aliyuncs.com/soft/ditie/settings.json" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *_array = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
if(_array){
[_array writeToFile:_settingPlistPath atomically:YES];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
} @catch (NSException *exception) {
}
});
}
@end