//
// AppDelegate.h
// test two
//
// Created by 刘皇帝 on 2018/12/10.
// Copyright © 2018 刘皇帝. All rights reserved.
//
#import
#import
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property(readonly,strong)NSPersistentContainer*persistentContainer;
- (void)saveContext;
@end
//
// AppDelegate.m
// test two
//
// Created by 刘皇帝 on 2018/12/10.
// Copyright © 2018 刘皇帝. All rights reserved.
//
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
return YES;
}
- (void)applicationWillResignActive:(UIApplication*)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication*)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication*)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication*)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication*)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
[self saveContext];
}
#pragma mark - Core Data stack
@synthesizepersistentContainer =_persistentContainer;
- (NSPersistentContainer*)persistentContainer {
// The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
@synchronized (self) {
if (_persistentContainer == nil) {
_persistentContainer= [[NSPersistentContaineralloc]initWithName:@"test_two"];
[_persistentContainerloadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription*storeDescription,NSError*error) {
if(error !=nil) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
NSLog(@"Unresolved error %@, %@", error, error.userInfo);
abort();
}
}];
}
}
return _persistentContainer;
}
#pragma mark - Core Data Saving support
- (void)saveContext {
NSManagedObjectContext *context = self.persistentContainer.viewContext;
NSError*error =nil;
if([contexthasChanges] && ![contextsave:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, error.userInfo);
abort();
}
}
@end
//
// ViewController.h
// test two
//
// Created by 刘皇帝 on 2018/12/10.
// Copyright © 2018 刘皇帝. All rights reserved.
//
#import
@interfaceViewController :UIViewController
@end
//
// ViewController.m
// test two
//
// Created by 刘皇帝 on 2018/12/10.
// Copyright © 2018 刘皇帝. All rights reserved.
//
#import "ViewController.h"
#import "SecondViewController.h"
#import
#import
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//导航条
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"附近违章高发地" style:UIBarButtonItemStyleDone target:self action:@selector(Cilck)];
[AMapServices sharedServices].enableHTTPS = YES;
///初始化地图
MAMapView*_mapView = [[MAMapViewalloc]initWithFrame:self.view.bounds];
///把地图添加至view
MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];
r.showsAccuracyRing = NO;///精度圈是否显示,默认YES
r.showsHeadingIndicator = NO;///是否显示方向指示(MAUserTrackingModeFollowWithHeading模式开启)。默认为YES
r.strokeColor = [UIColor blueColor];///精度圈 边线颜色, 默认 kAccuracyCircleDefaultColor
r.lineWidth = 2;///精度圈 边线宽度,默认0
// r.locationDotBgColor = [UIColor greenColor];///定位点背景色,不设置默认白色
r.fillColor= [UIColorredColor];
r.strokeColor= [UIColorblackColor];
[_mapViewupdateUserLocationRepresentation:r];
_mapView.showsUserLocation = YES;
_mapView.userTrackingMode = MAUserTrackingModeFollow;
[self.viewaddSubview:_mapView];
[AMapServices sharedServices].enableHTTPS = YES;
}
-(void)Cilck{
//跳转到违章的页面
SecondViewController *sec = [[SecondViewController alloc] init];
[self.navigationController pushViewController:sec animated:YES];
}
@end
//
// SecondViewController.h
// test two
//
// Created by 刘皇帝 on 2018/12/10.
// Copyright © 2018 刘皇帝. All rights reserved.
//
#import
NS_ASSUME_NONNULL_BEGIN
@interfaceSecondViewController :UIViewController
@end
NS_ASSUME_NONNULL_END
//
// SecondViewController.m
// test two
//
// Created by 刘皇帝 on 2018/12/10.
// Copyright © 2018 刘皇帝. All rights reserved.
//
#import "SecondViewController.h"
#import "AFNetworking.h"
#import "PostViewController.h"
@interface SecondViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *table;
@property(nonatomic,strong) NSMutableArray *dataScour;
@end
@implementationSecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
//设置头视图
self.title=@"查看违章";
_table = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
_table.delegate=self;
_table.dataSource = self;
[self.view addSubview:_table];
_dataScour = [[NSMutableArray alloc] init];
_dataScour = @[@"平泉路中监控抓拍",@"平泉路公交入口1闭路监控抓拍"];
NSDictionary*params = @{@"lat":@"经度",@"lon":@"纬度",@"key":@"6d96ee265cc090b418ee51257ff9c48f",@"page":@"dwad",@"pagesize":@"",@"r":@""};
[self postDateUrl:@"http://v.juhe.cn/wzpoints/query" body:params
];
}
- (void)postDateUrl:(NSString*)url body:(NSDictionary*)body
{
[PostViewControllergetDataWithString:urlbody:bodyblock:^(idblock) {
//block 是请求回得数据
}];
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return _dataScour.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text=_dataScour[indexPath.row];
returncell;
}
@end
//
// PostViewController.h
//
//
// Created by 刘皇帝 on 2018/12/10.
//
#import
#import "AFNetworking.h"
NS_ASSUME_NONNULL_BEGIN
typedefvoid(^AFNData)(idblock);
@interfacePostViewController :UIViewController
+(void)getDataWithString:(NSString*)string body:(NSDictionary*)parameters block:(AFNData)block;
@end
NS_ASSUME_NONNULL_END
//
// PostViewController.m
//
//
// Created by 刘皇帝 on 2018/12/10.
//
#import "PostViewController.h"
#import "AFNetworking.h"
@interface PostViewController ()
@end
@implementationPostViewController
- (void)viewDidLoad {
[super viewDidLoad];
AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
NSDictionary *dic = @{@"lat":@"string"};
[mangerPOST:@"http://v.juhe.cn/wzpoints/query"parameters:dicsuccess:^(NSURLSessionDataTask*_Nonnulltask,id _NullableresponseObject) {
NSLog(@"%@",responseObject);
}failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {
}];
}
+ (void)getDataWithString:(NSString*)string body:(NSDictionary*)parameters block:(AFNData)block
{
AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
NSString*url_string = [NSStringstringWithFormat:@"%@",string];
url_string = [url_stringstringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
// NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"参数1",@"lat",@"参数2",@"lon",@"参数3",@"key", nil];
[managerPOST:url_stringparameters:parameterssuccess:^(NSURLSessionTask*task,idresponseObject) {
// [netWorkManager stopMonitoring];
NSLog(@"%@",responseObject);
block(responseObject);
}failure:^(NSURLSessionTask*operation,NSError*error) {
NSLog(@"失败 === %@",error);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"Error: %@", error);
});
}];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
网友评论