-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathViewController.m
443 lines (393 loc) · 16.8 KB
/
ViewController.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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
//
// ViewController.m
// LLDebugToolDemo
//
// Created by Li on 2018/3/15.
// Copyright © 2018年 li. All rights reserved.
//
#import "ViewController.h"
// If you integrate with cocoapods, used #import <LLDebug.h>.
#import "LLDebug.h"
// Used to example.
#import <CoreLocation/CoreLocation.h>
#import <Photos/PHPhotoLibrary.h>
#import "NetTool.h"
#import "TestColorStyleViewController.h"
#import "TestCrashViewController.h"
#import "TestHierarchyViewController.h"
#import "TestHtmlViewController.h"
#import "TestLocationViewController.h"
#import "TestLogViewController.h"
#import "TestNetworkViewController.h"
#import "TestShortCutViewController.h"
#import "TestWindowStyleViewController.h"
#import "LLStorageManager.h"
static NSString *const kCellID = @"cellID";
@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) CLLocationManager *locationManager;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// LLDebugTool need time to start.
sleep(0.5);
[self doSomeActions];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
#pragma mark - Primary
- (void)doSomeActions {
[self requestPhotoAuthorization];
[self requestLocationAuthorization];
[self doSandboxIfNeeded];
[self doCrashIfNeeded];
[self doNetwork];
[self doLog];
}
- (void)requestPhotoAuthorization {
// Try to get album permission, and if possible, screenshots are stored in the album at the same time.
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
}];
}
- (void)requestLocationAuthorization {
// Try to get location permission, and if possible, mock location will get your current location.
self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager requestWhenInUseAuthorization];
}
- (void)doCrashIfNeeded {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"openCrash"]) {
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"openCrash"];
[[NSUserDefaults standardUserDefaults] synchronize];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[LLDebugTool sharedTool] executeAction:LLDebugToolActionCrash];
});
}
}
- (void)doSandboxIfNeeded {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSArray *extensions = @[@"gif", @"html", @"jpg", @"json", @"md", @"mp3", @"mp4", @"pdf", @"plist", @"png", @"txt"];
for (NSString *extension in extensions) {
[self copyFileWithExtensionIfNeeded:extension];
}
});
}
- (void)copyFileWithExtensionIfNeeded:(NSString *)extension {
if ([extension length] == 0) {
return;
}
NSFileManager *manager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *targetPath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"LLDebugTool.%@", extension]];
if (![manager fileExistsAtPath:targetPath]) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"LLDebugTool" ofType:extension];
if (path) {
NSError *error = nil;
if (![manager copyItemAtPath:path toPath:targetPath error:&error]) {
NSLog(@"Copy resource failed");
}
}
}
}
- (void)doNetwork {
__block __weak typeof(self) weakSelf = self;
//Network Request
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1567589759362&di=20c415aa38f25ca77270c717ae988424&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201602%2F15%2F20160215231800_zrCN8.jpeg"]];
[urlRequest setHTTPMethod:@"GET"];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[NSURLConnection sendAsynchronousRequest:urlRequest
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *_Nullable response, NSData *_Nullable data, NSError *_Nullable connectionError) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!connectionError) {
UIImage *image = [[UIImage alloc] initWithData:data];
weakSelf.imgView.image = image;
}
});
}];
#pragma clang diagnostic pop
// Json Response
[[NetTool shared]
.afHTTPSessionManager GET:@"http://baike.baidu.com/api/openapi/BaikeLemmaCardApi?&format=json&appid=379020&bk_key=%E7%81%AB%E5%BD%B1%E5%BF%8D%E8%80%85&bk_length=600"
parameters:nil
progress:nil
success:^(NSURLSessionDataTask *_Nonnull task, id _Nullable responseObject) {
}
failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error){
}];
//NSURLSession
NSMutableURLRequest *htmlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com"]];
[htmlRequest setHTTPMethod:@"GET"];
NSURLSessionDataTask *dataTask = [[NetTool shared]
.session dataTaskWithRequest:htmlRequest
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
}];
[dataTask resume];
}
- (void)doLog {
// Log.
// NSLocalizedString is used for multiple languages.
// You can just use as LLog(@"What you want to pring").
LLog(NSLocalizedString(@"initial.log", nil));
LLog_Alert_Event(@"Demo", NSLocalizedString(@"initial.log", nil));
}
#pragma mark - Actions
- (void)testColorConfig {
TestColorStyleViewController *vc = [[TestColorStyleViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)testWindowStyle {
TestWindowStyleViewController *vc = [[TestWindowStyleViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)testNetwork {
TestNetworkViewController *vc = [[TestNetworkViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)testLog {
TestLogViewController *vc = [[TestLogViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)testCrash {
TestCrashViewController *vc = [[TestCrashViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)testAppInfo {
[[LLDebugTool sharedTool] executeAction:LLDebugToolActionAppInfo];
}
- (void)testSandbox {
[[LLDebugTool sharedTool] executeAction:LLDebugToolActionSandbox];
}
- (void)testScreenshot {
[[LLDebugTool sharedTool] executeAction:LLDebugToolActionConvenientScreenshot];
}
- (void)testHierarchy {
TestHierarchyViewController *vc = [[TestHierarchyViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)testMagnifier {
[[LLDebugTool sharedTool] executeAction:LLDebugToolActionMagnifier];
}
- (void)testRuler {
[[LLDebugTool sharedTool] executeAction:LLDebugToolActionRuler];
}
- (void)testWidgetBorder {
[[LLDebugTool sharedTool] executeAction:LLDebugToolActionWidgetBorder];
}
- (void)testHtml {
TestHtmlViewController *vc = [[TestHtmlViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)testLocation {
TestLocationViewController *vc = [[TestLocationViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)testShortCut {
TestShortCutViewController *vc = [[TestShortCutViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 14;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 2;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = nil;
cell.textLabel.numberOfLines = 0;
cell.detailTextLabel.text = nil;
cell.detailTextLabel.numberOfLines = 0;
cell.accessoryType = UITableViewCellAccessoryNone;
if (indexPath.section == 0) {
if (indexPath.row == 0) {
cell.textLabel.text = NSLocalizedString(@"test.color.style", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
switch ([LLConfig shared].colorStyle) {
case LLConfigColorStyleHack: {
cell.detailTextLabel.text = @"LLConfigColorStyleHack";
} break;
case LLConfigColorStyleSimple: {
cell.detailTextLabel.text = @"LLConfigColorStyleSimple";
} break;
case LLConfigColorStyleSystem: {
cell.detailTextLabel.text = @"LLConfigColorStyleSystem";
} break;
case LLConfigColorStyleGrass: {
cell.detailTextLabel.text = @"LLConfigColorStyleGrass";
} break;
case LLConfigColorStyleHomebrew: {
cell.detailTextLabel.text = @"LLConfigColorStyleHomebrew";
} break;
case LLConfigColorStyleManPage: {
cell.detailTextLabel.text = @"LLConfigColorStyleManPage";
} break;
case LLConfigColorStyleNovel: {
cell.detailTextLabel.text = @"LLConfigColorStyleNovel";
} break;
case LLConfigColorStyleOcean: {
cell.detailTextLabel.text = @"LLConfigColorStyleOcean";
} break;
case LLConfigColorStylePro: {
cell.detailTextLabel.text = @"LLConfigColorStylePro";
} break;
case LLConfigColorStyleRedSands: {
cell.detailTextLabel.text = @"LLConfigColorStyleRedSands";
} break;
case LLConfigColorStyleSilverAerogel: {
cell.detailTextLabel.text = @"LLConfigColorStyleSilverAerogel";
} break;
case LLConfigColorStyleSolidColors: {
cell.detailTextLabel.text = @"LLConfigColorStyleSolidColors";
} break;
case LLConfigColorStyleCustom: {
cell.detailTextLabel.text = @"LLConfigColorStyleCustom";
} break;
}
} else if (indexPath.row == 1) {
cell.textLabel.text = NSLocalizedString(@"test.window.style", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
switch ([LLConfig shared].entryWindowStyle) {
case LLConfigEntryWindowStyleBall: {
cell.detailTextLabel.text = @"LLConfigEntryWindowStyleBall";
} break;
case LLConfigEntryWindowStyleTitle: {
cell.detailTextLabel.text = @"LLConfigEntryWindowStyleTitle";
} break;
case LLConfigEntryWindowStyleLeading: {
cell.detailTextLabel.text = @"LLConfigEntryWindowStyleLeading";
} break;
case LLConfigEntryWindowStyleTrailing: {
cell.detailTextLabel.text = @"LLConfigEntryWindowStyleTrailing";
} break;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
case LLConfigEntryWindowStylePowerBar: {
cell.detailTextLabel.text = @"LLConfigEntryWindowStylePowerBar";
} break;
case LLConfigEntryWindowStyleNetBar: {
cell.detailTextLabel.text = @"LLConfigEntryWindowStyleNetBar";
} break;
#pragma clang diagnostic pop
}
}
} else if (indexPath.section == 1) {
cell.textLabel.text = NSLocalizedString(@"test.network.request", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if (indexPath.section == 2) {
cell.textLabel.text = NSLocalizedString(@"test.log", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if (indexPath.section == 3) {
cell.textLabel.text = NSLocalizedString(@"test.crash", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if (indexPath.section == 4) {
cell.textLabel.text = NSLocalizedString(@"app.info", nil);
} else if (indexPath.section == 5) {
cell.textLabel.text = NSLocalizedString(@"sandbox.info", nil);
} else if (indexPath.section == 6) {
cell.textLabel.text = NSLocalizedString(@"test.screenshot", nil);
} else if (indexPath.section == 7) {
cell.textLabel.text = NSLocalizedString(@"test.hierarchy", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if (indexPath.section == 8) {
cell.textLabel.text = NSLocalizedString(@"test.magnifier", nil);
} else if (indexPath.section == 9) {
cell.textLabel.text = NSLocalizedString(@"test.ruler", nil);
} else if (indexPath.section == 10) {
cell.textLabel.text = NSLocalizedString(@"test.widget.border", nil);
} else if (indexPath.section == 11) {
cell.textLabel.text = NSLocalizedString(@"test.html", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if (indexPath.section == 12) {
cell.textLabel.text = NSLocalizedString(@"test.location", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if (indexPath.section == 13) {
cell.textLabel.text = NSLocalizedString(@"test.short.cut", nil);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
if (indexPath.row == 0) {
[self testColorConfig];
} else if (indexPath.row == 1) {
[self testWindowStyle];
}
} else if (indexPath.section == 1) {
[self testNetwork];
} else if (indexPath.section == 2) {
[self testLog];
} else if (indexPath.section == 3) {
[self testCrash];
} else if (indexPath.section == 4) {
[self testAppInfo];
} else if (indexPath.section == 5) {
[self testSandbox];
} else if (indexPath.section == 6) {
[self testScreenshot];
} else if (indexPath.section == 7) {
[self testHierarchy];
} else if (indexPath.section == 8) {
[self testMagnifier];
} else if (indexPath.section == 9) {
[self testRuler];
} else if (indexPath.section == 10) {
[self testWidgetBorder];
} else if (indexPath.section == 11) {
[self testHtml];
} else if (indexPath.section == 12) {
[self testLocation];
} else if (indexPath.section == 13) {
[self testShortCut];
}
[self.tableView reloadData];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
return @"LLConfig";
} else if (section == 1) {
return @"Network Request";
} else if (section == 2) {
return @"Log";
} else if (section == 3) {
return @"Crash";
} else if (section == 4) {
return @"App Info";
} else if (section == 5) {
return @"Sandbox Info";
} else if (section == 6) {
return @"Screen Shot";
} else if (section == 7) {
return @"Hierarchy";
} else if (section == 8) {
return @"Magnifier";
} else if (section == 9) {
return @"Ruler";
} else if (section == 10) {
return @"Widget Border";
} else if (section == 11) {
return @"Html";
} else if (section == 12) {
return @"Location";
} else if (section == 13) {
return @"Short Cut";
}
return nil;
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
@end