-
Notifications
You must be signed in to change notification settings - Fork 2
/
HistoryTrackViewController.m
1049 lines (775 loc) · 38.3 KB
/
HistoryTrackViewController.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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// HistoryTrackViewController.m
// Runner
//
// Created by 于恩聪 on 15/7/6.
// Copyright (c) 2015年 于恩聪. All rights reserved.
//
#import "HistoryTrackViewController.h"
#import "Mymapview.h"
#import "Networking.h"
#import "IQActionSheetPickerView.h"
#import "Networking.h"
#import "PRNAmrRecorder.h"
#import "PRNAmrPlayer.h"
#define PATH_OF_DOCUMENT [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
@interface HistoryTrackViewController()<UITableViewDataSource,UITableViewDelegate,IQActionSheetPickerViewDelegate,PRNAmrRecorderDelegate>
{
UIButton *firstButton;
UIButton *secondButton;
UIButton *thirdButton;
UIButton *fouthButton;
UIButton *selectedButton;
UIButton *searchButton;
UILabel *overLabel;
UIView *backView;
UITableView *listView;
UITableView *chatView;
NSMutableArray *typeArray;
NSMutableArray *contentArray;
NSMutableArray *timeArray;
NSString *pointContent;
NSString *showPoint;
int scanCount;
NSScanner *_scanner;
NSTimer *_scanTimer;
CLLocationCoordinate2D coordinates[2];
CLLocationCoordinate2D lastCoordinate;
MAPointAnnotation *lastAnnotation;
MAPointAnnotation *touchAnnotation;
IQActionSheetPickerView *picker;
NSMutableArray *urls;
NSMutableArray *sendTime;
NSMutableArray *fromTypes;
NSMutableArray *isHeards;
UIView *cellBgView;
PRNAmrRecorder *recorder;
PRNAmrPlayer *player;
BOOL outputMode;
NSString *shouhuan_id;
NSString *user_id;
}
@end
@implementation HistoryTrackViewController
@synthesize mapView,fenceChoice,dateButton;
- (void)viewDidLoad {
i = 0;
[super viewDidLoad];
recorder = [[PRNAmrRecorder alloc] init];
recorder.delegate = self;
player = [[PRNAmrPlayer alloc] init];
shouhuan_id = [[NSUserDefaults standardUserDefaults] objectForKey:@"shouhuan_id"];
user_id = [[NSUserDefaults standardUserDefaults ] objectForKey:@"user_id"];
[self initUI];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self initMapview];
}
- (void)viewWillDisappear:(BOOL)animated{
[_scanTimer invalidate];
[mapView setHidden:NO];
[mapView removeOverlays:mapView.overlays];
[mapView removeAnnotations:mapView.annotations];
}
- (void)initUI {
[self.view setBackgroundColor:[UIColor whiteColor]];
[self initView];
[self initDatePicker];
[self initTableView];
[self initButton];
[self initNavigation];
}
- (void)initNavigation {
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:252/255.0 green:92/255.0 blue:64/255.0 alpha:1]];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , 100, 44)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont boldSystemFontOfSize:17];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"历史管理"; //设置标
self.navigationItem.titleView= titleLabel;
}
- (void)initDatePicker {
picker = [[IQActionSheetPickerView alloc] initWithTitle:@"Date Picker" delegate:self];
[picker setTag:6];
[picker setActionSheetPickerStyle:IQActionSheetPickerStyleDatePicker];
}
- (void)initTableView {
listView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 150)];
listView.dataSource = self;
listView.delegate = self;
listView.showsVerticalScrollIndicator = NO;
listView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
[listView setHidden:NO];
[backView addSubview:listView];
sendTime = [NSMutableArray new];
urls = [NSMutableArray new];
fromTypes = [NSMutableArray new];
isHeards = [NSMutableArray new];
chatView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
chatView.backgroundColor = [UIColor whiteColor];
chatView.showsVerticalScrollIndicator = NO;
chatView.delegate = self;
chatView.dataSource = self;
chatView.frame = CGRectMake(0, 0, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 140);
chatView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
[chatView setHidden:YES];
[backView addSubview:chatView];
typeArray = [NSMutableArray new];
contentArray = [NSMutableArray new];
timeArray = [NSMutableArray new];
}
- (void)initMapview{
Mymapview *mymapView = [Mymapview sharedInstance];
[mymapView setFrame:CGRectMake(10, 141, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 150)];
mapView = mymapView.mapView;
[mapView removeOverlays:mapView.overlays];
[mapView removeAnnotations:mapView.annotations];
mapView.delegate = self;
[self.view addSubview:mymapView];
[self.view sendSubviewToBack:mymapView];
}
- (void)initView{
[self.view setBackgroundColor:DEFAULT_BACKGOUNDCOLOR];
backView = [[UIView alloc] initWithFrame:CGRectMake(10, 141, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 150)];
[backView setBackgroundColor:[UIColor whiteColor]];
[backView setHidden:YES];
[self.view addSubview:backView];
}
- (void)initButton {
dateButton = [[UIButton alloc]initWithFrame:CGRectMake(10, 70,100, 35)];
NSDate *senddate=[NSDate date];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"YYYY-MM-dd"];
NSString *locationString=[dateformatter stringFromDate:senddate];
[dateButton setTitle:locationString forState:UIControlStateNormal];
[dateButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[dateButton setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
[dateButton.titleLabel setTextAlignment:NSTextAlignmentLeft];
[dateButton addTarget:self action:@selector(pressedCalendar) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:dateButton];
CGFloat basicX = 10;
CGFloat basicMove = (SCREEN_WIDTH - 20) / 4;
firstButton = [self buttonWithTitle:@"足迹" andPointX:basicX];
secondButton = [self buttonWithTitle:@"语音" andPointX:basicX + basicMove];
thirdButton = [self buttonWithTitle:@"消息" andPointX:basicX + basicMove * 2];
fouthButton = [self buttonWithTitle:@"运动" andPointX:basicMove * 3 + basicX];
searchButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 100, 67, 90, 36)];
[searchButton setBackgroundColor:DEFAULTCOLOR];
[searchButton.titleLabel setTextColor:[UIColor whiteColor]];
[searchButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
[searchButton setTitle:@"搜索" forState:UIControlStateNormal];
[searchButton.layer setCornerRadius:6.f];
[searchButton.layer setBorderColor:[UIColor grayColor].CGColor];
[searchButton.layer setBorderWidth:0.3f];
[searchButton addTarget:self action:@selector(clickSearchButtonDown) forControlEvents:UIControlEventTouchUpInside];
[searchButton addTarget:self action:@selector(clickSearchButton) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:searchButton];
//点击 覆盖
overLabel = [[UILabel alloc] init];
[overLabel setBackgroundColor:DEFAULTCOLOR];
[overLabel setText:@"轨迹"];
[overLabel setTextAlignment:NSTextAlignmentCenter];
[overLabel setTextColor:[UIColor whiteColor]];
[overLabel setFrame:CGRectMake(6, 106, (SCREEN_WIDTH - 20) / 4, 36)];
selectedButton = firstButton;
[self.view addSubview:overLabel];
}
- (UIButton *)buttonWithTitle:(NSString *)title andPointX:(CGFloat)pointX {
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(pointX, 106,(SCREEN_WIDTH - 20)/4, 36)];
[button setBackgroundColor:[UIColor colorWithRed:252/255.0 green:92/255.0 blue:64/255.0 alpha:0.5]];
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setUserInteractionEnabled:NO];
[self.view addSubview:button];
return button;
}
//点击button 事件
- (void)pressedCalendar {
[picker show];
}
- (void)clickSearchButton {
NSLog(@"search");
[searchButton setBackgroundColor:[UIColor whiteColor]];
[searchButton setTitleColor:DEFAULTCOLOR forState:UIControlStateNormal];
if (selectedButton == fouthButton) {
[self getStepnum];
[chatView setHidden:YES];
[listView setHidden:NO];
}
if (selectedButton == thirdButton) {
[self getAlarmMessage];
[chatView setHidden:YES];
[listView setHidden:NO];
}
if (selectedButton == firstButton) {
[_scanTimer invalidate];
[mapView removeOverlays:mapView.overlays];
[mapView removeAnnotations:mapView.annotations];
[self getTrackMessage];
[chatView setHidden:YES];
[listView setHidden:YES];
}
if (selectedButton == secondButton){
[self getVoicMessage];
[chatView setHidden:NO];
[listView setHidden:YES];
}
}
- (void)clickSearchButtonDown{
[searchButton setBackgroundColor:DEFAULTCOLOR];
[searchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
- (void)getStepnum{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
NSLog(@"%@",dateButton.titleLabel.text);
if (!shouhuan_id) {
return;
}
NSDictionary *parameters = @{
@"shouhuan_id":shouhuan_id,
@"user_id":user_id,
@"start_time":[NSString stringWithFormat:@"%@ 00:00:01",dateButton.titleLabel.text],
@"end_time":[NSString stringWithFormat:@"%@ 23:59:59",dateButton.titleLabel.text]
};
NSString *url=@"http://101.201.211.114:8080/APIPlatform/getstepnum";
[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"SUCCESS JSON: %@", responseObject);
NSDictionary *dict = (NSDictionary *)responseObject;
NSString *code = [dict objectForKey:@"code"];
if ([code isEqualToString:@"100"]) {
NSLog(@"getstepsnum success");
NSString *tempData = [dict objectForKey:@"data"];
if (tempData.length <= 2) {
[self showAlertnoRecord];
return ;
}
NSRange range = {1,tempData.length - 2};
NSString *data = [tempData substringWithRange:range];
NSData *jsonData = [data dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
NSLog( @"dict : %@",jsonDict);
NSString *tempTime = [jsonDict objectForKey:@"time"];
NSRange _range = {0,10};
NSString *time = [tempTime substringWithRange:_range];
NSString *step_nums = [jsonDict objectForKey:@"step_num"];
NSLog(@"time %@ stem_num %@",time,step_nums);
timeArray = [NSMutableArray arrayWithObjects:time, nil];
contentArray = [NSMutableArray arrayWithObjects:step_nums, nil];
[listView reloadData];
NSLog(@"%@",data);
}
if ([code isEqualToString:@"200"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"用户名或密码错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
if ([code isEqualToString:@"500"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"系统内部错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
- (void)getAlarmMessage {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
NSDictionary *parameters = @{
@"shouhuan_id":shouhuan_id,
@"user_id":user_id,
@"start_time":[NSString stringWithFormat:@"%@ 00:00:01",dateButton.titleLabel.text],
@"end_time":[NSString stringWithFormat:@"%@ 23:59:59",dateButton.titleLabel.text]
};
NSString *url=@"http://101.201.211.114:8080/APIPlatform/getcrossandsos";
[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"SUCCESS JSON: %@", responseObject);
NSDictionary *dict = (NSDictionary *)responseObject;
NSString *code = [dict objectForKey:@"code"];
if ([code isEqualToString:@"100"]) {
NSLog(@"getAlarmMessage success");
NSString *tempData = [dict objectForKey:@"data"];
if (tempData.length <= 2) {
[self showAlertnoRecord];
return ;
}
NSRange range = {1,tempData.length - 2};
NSString *data = [tempData substringWithRange:range];
NSArray *fenceArray = [data componentsSeparatedByString:@"}"];
NSLog(@"fenceArray : %@",fenceArray);
for (int j = 0; j < fenceArray.count - 1; j ++) {
NSString *firstFenceTemp = [fenceArray objectAtIndex:j];
if (j > 0) {
NSRange _range = {1,firstFenceTemp.length - 1};
firstFenceTemp = [firstFenceTemp substringWithRange:_range];
}
NSString *fenceMessage = [NSString stringWithFormat:@"%@}",firstFenceTemp];
NSData *jsonData = [fenceMessage dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
NSLog( @"dict : %@",jsonDict);
NSString *sign = [NSString stringWithFormat:@"%@",[jsonDict objectForKey:@"sign"]];
if([sign isEqualToString:@"2"]){
[contentArray addObject:@"低电报警"];
}
if ([sign isEqualToString:@"5"]) {
[contentArray addObject:@"SOS报警"];
}
if ([sign isEqualToString:@"3"]) {
[contentArray addObject:@"手环拆除报警"];
}
NSString *point = [jsonDict objectForKey:@"point"];
NSString *time = [jsonDict objectForKey:@"time"];
[timeArray addObject:time];
[typeArray addObject:@"手环报警"];
NSLog(@"point %@,sign %@,time %@",point,sign,time);
}
[listView reloadData];
}
if ([code isEqualToString:@"200"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"用户名或密码错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
if ([code isEqualToString:@"500"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"系统内部错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
- (void)getVoicMessage {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
NSDictionary *parameters = @{
@"shouhuan_id":shouhuan_id,
@"user_id":user_id,
@"start_time":[NSString stringWithFormat:@"%@ 00:00:01",dateButton.titleLabel.text],
@"end_time":[NSString stringWithFormat:@"%@ 23:59:59",dateButton.titleLabel.text]
};
NSString *url=@"http://101.201.211.114:8080/APIPlatform/gethistoryrecord";
[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *dict = (NSDictionary *)responseObject;
NSString *code = [dict objectForKey:@"code"];
if ([code isEqualToString:@"100"]) {
NSString *tempData = [dict objectForKey:@"data"];
if (tempData.length <= 2) {
return ;
}
NSRange range = {1,tempData.length - 2};
NSString *data = [tempData substringWithRange:range];
NSArray *fenceArray = [data componentsSeparatedByString:@"}"];
for (int j = 0; j < fenceArray.count - 1; j ++) {
NSString *firstFenceTemp = [fenceArray objectAtIndex:j];
if (j > 0) {
NSRange _range = {1,firstFenceTemp.length - 1};
firstFenceTemp = [firstFenceTemp substringWithRange:_range];
}
NSString *fenceMessage = [NSString stringWithFormat:@"%@}",firstFenceTemp];
NSData *jsonData = [fenceMessage dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
NSString *url = [jsonDict objectForKey:@"url"];
NSString *time = [jsonDict objectForKey:@"time"];
NSString *isHeard = [jsonDict objectForKey:@"isHeard"];
NSString *from_type = [jsonDict objectForKey:@"from_type"];
NSLog(@"url : %@",url);
[self getVoiceDetailMessageByfilename:url];
[urls addObject:url];
[sendTime addObject:time];
[isHeards addObject:isHeard];
[fromTypes addObject:from_type];
}
[chatView reloadData];
}
if ([code isEqualToString:@"200"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"用户名或密码错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
if ([code isEqualToString:@"500"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"系统内部错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
- (void)getVoiceDetailMessageByfilename:(NSString *)fileName{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"multipart/form-data"];
NSDictionary *parameters = @{
@"url":fileName,
@"shouhuan_id":shouhuan_id,
@"user_id":user_id,
};
NSString *url=@"http://101.201.211.114:8080/APIPlatform/recorddownload";
[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSData *amrdata = [operation responseData];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:fileName];
[amrdata writeToFile:filePath atomically:YES];
[[NSUserDefaults standardUserDefaults] setObject:amrdata forKey:@"amrtestdata"];
NSDictionary *dict = (NSDictionary *)responseObject;
NSString *code = [dict objectForKey:@"code"];
if ([code isEqualToString:@"100"]) {
NSLog(@"getVoicMessage success");
}
if ([code isEqualToString:@"200"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"用户名或密码错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
if ([code isEqualToString:@"500"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"系统内部错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"失败 : %@",error);
}];
}
- (void)getTrackMessage {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
NSDictionary *parameters = @{
@"shouhuan_id":shouhuan_id,
@"user_id":user_id,
@"start_time":[NSString stringWithFormat:@"%@ 00:00:01",dateButton.titleLabel.text],
@"end_time":[NSString stringWithFormat:@"%@ 23:59:59",dateButton.titleLabel.text]
};
NSString *url=@"http://101.201.211.114:8080/APIPlatform/historylocation";
[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"SUCCESS JSON: %@", responseObject);
NSDictionary *dict = (NSDictionary *)responseObject;
NSString *code = [dict objectForKey:@"code"];
if ([code isEqualToString:@"100"]) {
NSLog(@"getTrackMessage success");
NSString *tempData = [dict objectForKey:@"data"];
if (tempData.length <= 2) {
[self showAlertnoRecord];
return ;
}
NSRange range = {1,tempData.length - 2};
NSString *data = [tempData substringWithRange:range];
NSArray *fenceArray = [data componentsSeparatedByString:@"}"];
NSLog(@"fenceArray : %@",fenceArray);
pointContent = [NSString new];
for (int j = 0; j < fenceArray.count - 1; j ++) {
NSString *firstFenceTemp = [fenceArray objectAtIndex:j];
if (j > 0) {
NSRange _range = {1,firstFenceTemp.length - 1};
firstFenceTemp = [firstFenceTemp substringWithRange:_range];
}
NSString *fenceMessage = [NSString stringWithFormat:@"%@}",firstFenceTemp];
NSData *jsonData = [fenceMessage dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
NSLog( @"dict : %@",jsonDict);
NSString *point = [jsonDict objectForKey:@"point"];
NSLog(@"point : %@",point);
pointContent = [NSString stringWithFormat:@"%@,%@",pointContent,point];
}
NSLog(@"pointContent : %@",pointContent);
[self getTrack];
}
if ([code isEqualToString:@"200"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"用户名或密码错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
if ([code isEqualToString:@"500"]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"系统内部错误" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
//画annotation的回调函数
//画annotation的回调函数
- (MAAnnotationView *)mapView:(MAMapView *)_mapView viewForAnnotation:(id<MAAnnotation>)_annotation{
if ([_annotation isKindOfClass:[MAPointAnnotation class]])
{
NSLog(@"point");
static NSString *reuseIndetifier = @"annotationReuseIndetifier";
MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[_mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
if (annotationView == nil)
{
annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:reuseIndetifier];
}
annotationView.pinColor = MAPinAnnotationColorGreen;
annotationView.canShowCallout = YES;
annotationView.animatesDrop = NO;
if (_annotation == touchAnnotation) {
annotationView.image = [UIImage imageNamed:@"animationView"];
}else{
annotationView.image = [UIImage imageNamed:@"trackPoint"];
}
[annotationView setClipsToBounds:YES];
[annotationView setFrame:CGRectMake(0, 0, 10, 10)];
return annotationView;
}
return nil;
}
- (MAOverlayView *)mapView:(MAMapView *)_mapView viewForOverlay:(id <MAOverlay>)overlay
{
//画圆的回调函数
if ([overlay isKindOfClass:[MACircle class]])
{
MACircleView *circleView = [[MACircleView alloc] initWithCircle:overlay];
circleView.lineWidth = 5.f;
circleView.strokeColor = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.8];
circleView.fillColor = [UIColor colorWithRed:1.0 green:0.8 blue:0.0 alpha:0.8];
circleView.lineDash = YES;
return circleView;
}
//画折线的回调函数
if ([overlay isKindOfClass:[MAPolyline class]])
{
MAPolylineView *polylineView = [[MAPolylineView alloc] initWithPolyline:overlay];
polylineView.lineWidth = 2.f;
polylineView.strokeColor = [UIColor colorWithRed:3/255.0 green:169/255.0 blue:245/255.0 alpha:1];
polylineView.fillColor = [UIColor colorWithRed:3/255.0 green:169/255.0 blue:245/255.0 alpha:1];
polylineView.lineJoinType = kMALineJoinRound;//连接类型
polylineView.lineCapType = kMALineCapRound;//端点类型
return polylineView;
}
//多边形的回调函数
if ([overlay isKindOfClass:[MAPolygon class]])
{
MAPolygonView *polygonView = [[MAPolygonView alloc] initWithPolygon:overlay];
polygonView.lineWidth = 5.f;
polygonView.strokeColor = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.8];
polygonView.fillColor = [UIColor colorWithRed:0.77 green:0.88 blue:0.94 alpha:0.8];
polygonView.lineJoinType = kMALineJoinMiter;//连接类型
return polygonView;
}
return nil;
}
-(void)actionSheetPickerView:(IQActionSheetPickerView *)pickerView didSelectDate:(NSDate *)date
{
NSLog(@"picker.date : %@",date);
NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
formatter.dateFormat = @"YYYY-MM-dd";
[dateButton setTitle:[formatter stringFromDate:date] forState:UIControlStateNormal];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touch");
UITouch *touch = [[event allTouches]anyObject];
CGPoint point = [touch locationInView:self.view];
if (CGRectContainsPoint(firstButton.frame, point)) {
selectedButton = firstButton;
overLabel.frame = firstButton.frame;
overLabel.text = firstButton.titleLabel.text;
[mapView setHidden:NO];
[backView setHidden:YES];
typeArray = [NSMutableArray new];
contentArray = [NSMutableArray new];
timeArray = [NSMutableArray new];
}
if (CGRectContainsPoint(secondButton.frame, point)) {
selectedButton = secondButton;
overLabel.frame = secondButton.frame;
overLabel.text = secondButton.titleLabel.text;
[mapView setHidden:YES];
[backView setHidden:NO];
typeArray = [NSMutableArray new];
contentArray = [NSMutableArray new];
timeArray = [NSMutableArray new];
[listView reloadData];
[chatView setHidden:NO];
[listView setHidden:YES];
}
if (CGRectContainsPoint(thirdButton.frame, point)) {
selectedButton = thirdButton;
overLabel.frame = thirdButton.frame;
overLabel.text = thirdButton.titleLabel.text;
[mapView setHidden:YES];
[backView setHidden:NO];
typeArray = [NSMutableArray new];
contentArray = [NSMutableArray new];
timeArray = [NSMutableArray new];
[listView reloadData];
[listView setHidden:NO];
[chatView setHidden:YES];
}
if (CGRectContainsPoint(fouthButton.frame, point)) {
selectedButton = fouthButton;
overLabel.frame = fouthButton.frame;
overLabel.text = fouthButton.titleLabel.text;
[mapView setHidden:YES];
[backView setHidden:NO];
typeArray = [NSMutableArray new];
contentArray = [NSMutableArray new];
timeArray = [NSMutableArray new];
[listView reloadData];
[listView setHidden:NO];
[chatView setHidden:YES];
}
}
//table回调函数
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == chatView) {
return 65;
}
return 45;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == chatView) {
return urls.count;
}
return timeArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CMainCell = @"CMainCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CMainCell];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CMainCell];
}
if (tableView == chatView) {
for (UIView *view in cell.subviews) {
[view removeFromSuperview];
}
NSLog(@"chatviewcell : %@",indexPath);
cellBgView = [[UIView alloc] initWithFrame:CGRectMake(6, 7, SCREEN_WIDTH - 32, 36)];
//头像
UIImageView *portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(3, 3, 30, 30)];
[portraitView.layer setCornerRadius:15.f];
NSData *imageData = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@.protrait",shouhuan_id]];
if (imageData) {
UIImage *portraitImage = [UIImage imageWithData:imageData];
[portraitView setImage:portraitImage];
}
[portraitView.layer setCornerRadius:6.f];
[portraitView setClipsToBounds:YES];
[cellBgView addSubview:portraitView];
//消息体
UIButton *playButton = [[UIButton alloc] initWithFrame:CGRectMake(36, 5, 150, 36) ];
[playButton setTag:[indexPath row]];
[playButton setBackgroundImage:[UIImage imageNamed:@"chatCell"] forState:UIControlStateNormal];
[playButton addTarget:self action:@selector(playRecord:) forControlEvents:UIControlEventTouchUpInside];
[playButton setClipsToBounds:YES];
[playButton setTag:[indexPath row]];
//静态时图标
UIImageView *readStatus = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"readStatus"]];
readStatus.frame = CGRectMake(35, 8, 10, 20);
[playButton addSubview:readStatus];
[cellBgView addSubview:playButton];
UILabel *sendTimelabel = [UILabel new];
sendTimelabel.text = [sendTime objectAtIndex:(sendTime.count - 1 - [indexPath row])];
sendTimelabel.textAlignment = NSTextAlignmentCenter;
sendTimelabel.font = [UIFont systemFontOfSize:10];
sendTimelabel.frame = CGRectMake(0, 0, SCREEN_WIDTH - 20, 10);
[cell addSubview:sendTimelabel];
[cell addSubview:cellBgView];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSLog(@"%ld",(long)[indexPath row]);
return cell;
}
for (UIView *view in cell.subviews) {
[view removeFromSuperview];
}
//类型标签
UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH / 2, 45)];
if (selectedButton == fouthButton) {
[typeLabel setText:@"当日计步数"];
}else {
[typeLabel setText:[typeArray objectAtIndex:[indexPath row]]];
}
[typeLabel setTextAlignment:NSTextAlignmentLeft];
[typeLabel setTextColor:[UIColor blackColor]];
[typeLabel setFont:[UIFont systemFontOfSize:12]];
[cell addSubview:typeLabel];
[cell.textLabel setTextAlignment:NSTextAlignmentLeft];
[cell.textLabel setTextColor:[UIColor blackColor]];
[cell.textLabel setFont:[UIFont systemFontOfSize:14]];
//时间标签
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, SCREEN_WIDTH - 20, 10)];
NSString *time = [timeArray objectAtIndex:[indexPath row]];
[timeLabel setText:time];
[timeLabel setTextAlignment:NSTextAlignmentCenter];
[timeLabel setTextColor:[UIColor blackColor]];
[timeLabel setFont:[UIFont systemFontOfSize:12]];
[cell addSubview:timeLabel];
NSLog(@"timeLabel");
// 内容标签
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2 + 20, 0, SCREEN_WIDTH/2 - 10, 45)];
NSString *content = [NSString stringWithFormat:@"%@",[contentArray objectAtIndex:[indexPath row]]];
[contentLabel setText:content];
[contentLabel setTextColor:[UIColor blackColor]];
[contentLabel setTextAlignment:NSTextAlignmentLeft];
[contentLabel setFont:[UIFont systemFontOfSize:14]];
[cell addSubview:contentLabel];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
- (void)playRecord:(UIButton *)sender {
NSString *recordFile = [PATH_OF_DOCUMENT stringByAppendingPathComponent:[urls objectAtIndex:(urls.count - 1 - sender.tag)]];
NSLog(@"%@",[urls objectAtIndex:urls.count - 1 - sender.tag]);
[player setSpeakMode:outputMode];
[player playWithURL:[NSURL URLWithString:recordFile]];
}
- (void)getTrack{
double pointX;
double pointY = 0.0;
NSScanner *scanner = [NSScanner scannerWithString:pointContent];
do{
[scanner scanDouble:&pointX];
if (scanner.scanLocation < pointContent.length) {
scanner.scanLocation ++;
}
if (![scanner isAtEnd]) {
[scanner scanDouble:&pointY];
scanner.scanLocation ++;
}
if (pointY && pointX) {
showPoint = [NSString stringWithFormat:@"%@,%f,%f",showPoint,pointX,pointY];
}
}while (![scanner isAtEnd]);
_scanner = [NSScanner scannerWithString:showPoint];
_scanTimer = [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(showTrackByPoints) userInfo:nil repeats:YES];
}
- (void)showTrackByPoints{
double pointX;
double pointY;
if (!_scanner) {
_scanner = [NSScanner scannerWithString:showPoint];
}
if (_scanner.scanLocation < showPoint.length - 20 ) {
[_scanner scanDouble:&pointX];
if (_scanner.scanLocation < pointContent.length - 20) {
_scanner.scanLocation ++;