后台定位更新
来源:互联网 发布:渡边麻友ins事件 知乎 编辑:程序博客网 时间:2024/06/06 08:45
关于定位
官方推荐的有三种
- The significant-change location service (Recommended)
- Foreground-only location services
- Background location services
一般就前两种混合用的, 在 - (void)applicationDidEnterBackground:(UIApplication *)application
里面作出判断(把gps的关掉, 打开信号定位), 前提是你需要程序在后台的时候也定位的话
如何能够在后台间隔获取信息并不显示定位图标
因为apple一般情况下只允许程序在后台最多运行600秒, 所以, 我目前能想到的解决方案就是:
在plist里面设置允许后台定位
An app that provides continuous location updates to the user (even when in the background) can enable background location services by including the UIBackgroundModes key (with the location value) in its Info.plist file.
在applicationDidEnterBackground中设置后台需要运行的代码
- (void)applicationDidEnterBackground:(UIApplication *)application{ self.inBackground = YES; [self.locationManager stopUpdatingLocation]; UIBackgroundTaskIdentifier __block bgTask; bgTask = [application beginBackgroundTaskWithExpirationHandler:^{ // Clean up any unfinished task business by marking where you. // stopped or ending the task outright. [application endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; // Start the long-running task and return immediately. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ while (self.inBackground) { [self startLocationServices]; [NSThread sleepForTimeInterval:(550)]; } [application endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; });}
在这里开关定位, 不然的话会一直显示图标..
- (void)startLocationServices{ [self.locationManager startUpdatingLocation]; DLOG(@"timer start location service here"); DLOG(@"%f",[UIApplication sharedApplication].backgroundTimeRemaining);}
结束语
我怎么感觉每次我要做一个功能的实现方式都这么蛋疼…
不知道这么做能不能通过审核, 目前来说我还是倾向于用苹果推荐的后台信号监控定位的方式..
0 0
- ios后台定位更新
- 后台定位更新
- 后台定位
- 后台更新
- ios后台刷新,后台定位,后台下载
- IOS 后台定位
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS 后台定位
- 朋友之树
- Android入门笔记之Fragment
- 关于a=1++
- 二叉树的祖先结点,删除,插入,查找,前驱结点,后继结点等
- Ansi,UTF8,Unicode编码
- 后台定位更新
- php远程抓取网站图片并保存
- android用不锁屏设置
- Android开源项目SlidingMenu深入剖析
- mt6589 禁用虚拟按键 Navigation Bar
- Number Sequence 当f[i]==f[2]&&f[i-1]==f[1],周期=i-2
- 属性过滤器的应用
- Android bootanimation 制作过程
- 如何写paper