一、配置高德或百度的后台定位框架和代码(略)。

二、配置app不被系统kill,定时获取地理位置信息,并上传服务器(AppDelegate里面)。

具体代码:

1、

- (void)applicationDidEnterBackground:(UIApplication *)application {

    //控制定时器不被kill
UIApplication * app = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier bgTask;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
if (bgTask != UIBackgroundTaskInvalid) {
bgTask = UIBackgroundTaskInvalid;
}
});
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (bgTask != UIBackgroundTaskInvalid) {
bgTask = UIBackgroundTaskInvalid ;
}
});
}); }

2、

{
//全局计时器
NSTimer * timer;
}
-(void)turnOnTimer{
//14400.0 秒调用一次
timer = [NSTimer scheduledTimerWithTimeInterval:14400.0 target:self selector:@selector(pushGPSdata) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}

3、

-(void)pushGPSdata{

    //_dicUrl 全局保存定位信息
NSString * cityName = [NSString stringWithFormat:@"%@",_dicUrl[@"cityName"]];
NSString * latitude = [NSString stringWithFormat:@"%@",_dicUrl[@"latitude"]];
NSString * longitude = [NSString stringWithFormat:@"%@",_dicUrl[@"longitude"]]; if (cityName.length !=0&&latitude.length !=0&&longitude.length !=0) {
[self pushGPS:_dicUrl];
}
}
-(void)pushGPS:(NSMutableDictionary*)dic{ [com afPostRequestWithUrlString:trail_Url parms:dic finishedBlock:^(id responseObj) { NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableLeaves error:nil];
NSLog(@"%@",dic[@"message"]);
NSString * userStatus = [NSString stringWithFormat:@"%@",dic[@"success"]];
if ([userStatus isEqualToString:@"1"]) {
NSLog(@"GPS成功");
}else{
NSLog(@"GPS失败");
}
} failedBlock:^(NSString *errorMsg) {
}];
}

最新文章

  1. 将本地的新建的web Form页面放到服务器提示错误;
  2. Java Hour 66 Spring 相关
  3. git流程及操作
  4. C#winform项目添加引用编译文件
  5. Log设计
  6. NSTimer定时器类
  7. [改善Java代码]提防包装类型的null值
  8. jQuery 自定义事件的学习笔记
  9. Windows phone 之Socket
  10. [原]MobileSubstrate 工作流程
  11. Mybatis一对多查询得不到多方结果
  12. RabbitMQ安装步骤
  13. C++对C的函数拓展 - 默认参数
  14. Jetson TX2(3)opencv3 打开usb摄像头
  15. 开源代码chat_master分析
  16. Javascript高级编程学习笔记(82)—— 富文本操作(2)
  17. j旧学习
  18. [luogu3391][文艺平衡树]
  19. Linux 系统查看对应公网映射地址
  20. web(八)CSS选择器

热门文章

  1. BZOJ 2049 [Sdoi2008]Cave 洞穴勘测 ——Link-Cut Tree
  2. AFNetworking 之于 https 认证
  3. 后缀数组 POJ 2406 Power Strings
  4. BestCoder Round #73 (div.2)
  5. hdfs 集群间拷贝
  6. Shell 编程基础之 Case 练习
  7. [转]linux(centos)搭建SVN服务器
  8. Codeforces Round #196 (Div. 2) B. Routine Problem
  9. 通过data:image/png;base64把图片直接写在src里
  10. How to create a project with Oracle Policy Modeling