IOS后台定位
来源:互联网 发布:各行业数据查询 编辑:程序博客网 时间:2024/05/22 16:53
音乐和定位可以在后台一直运行着,前提是用户同意
直接上代码
//// ViewController.m// DingweiTest//// Created by user on 15/9/7.// Copyright (c) 2015年 ron. All rights reserved.//#import <CoreLocation/CoreLocation.h>#import "ViewController.h"@interface ViewController ()<UIAccelerometerDelegate , CLLocationManagerDelegate> { CLLocationManager *locationManager;}@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; locationManager = [[CLLocationManager alloc] init];//初始化定位器 [locationManager setDelegate: self];//设置代理 [locationManager setDesiredAccuracy: kCLLocationAccuracyBest];//设置精确度 [locationManager startUpdatingLocation];//开启位置更新 locationManager.pausesLocationUpdatesAutomatically = NO; // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"1123123123");}- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"error");}@end
还有2个地方要设置,一个是background modes 设置location updates
另外一个info.plist添加
NSLocationAlwaysUsageDescription -- String -- 我们需要通过您的地理位置来获取周边数据(这里文字随意)
0 0
- ios后台定位更新
- IOS 后台定位
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS后台定位实现
- iOS 后台定位
- iOS后台定位实现
- iOS 后台持续定位
- IOS后台定位
- iOS 后台定位
- 第2周项目0 宣告“主权”
- 非负矩阵分解NMF
- 第一个任务
- COCI2014/2015CONTEST #3 honi&stogovi(LCA)
- Python学习写一小程序,从某一目录下所以文件中查询某字段,并显示文件名和所在行
- IOS后台定位
- 免费SVN地址
- 第一周项目 C/C++语言中函数参数传递的三种方式
- 2015腾讯校园招聘软件测试部分笔试题
- matlab函数——shading函数
- 密码123456,这意味着什么?
- Hadoop基本命令
- Redis学习笔记(五)--排序
- ViewPager切换时粘滞视差的效果--模仿美丽说HIGO全球买手圈的滑动效果