iOS7.0以上 完整定位
来源:互联网 发布:卡盟主站域名填大全 编辑:程序博客网 时间:2024/05/19 00:07
1.导入2个系统框架
import CoreLocation
import MapKit
2.在plist里面添加字段
NSLocationAlwaysUsageDescription 或者 NSLocationWhenInUseUsageDescription 或者都添加
3.在func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
if CLLocationManager.locationServicesEnabled() {
manager.delegate = self
manager.startUpdatingLocation()
}else {
UIAlertView(title: "定位服务无法使用,请开启手机定位服务.", message: nil, delegate: nil, cancelButtonTitle: "知道了").show()
}
4.func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {//授权检察
preAuthorStatus = status
switch status {
case .NotDetermined://未选择
if manager.respondsToSelector(Selector("requestAlwaysAuthorization")) {
manager.requestAlwaysAuthorization()
}
case .Restricted://受限
showAlert("定位服务无法使用,请开启手机定位服务.", nil, nil, byVC: nil, nil)
case .Denied://拒绝
let actions = [
UIAlertAction(title: "关闭", style: .Cancel, handler: nil),
UIAlertAction(title: "前去设置", style: .Default, handler: { (action: UIAlertAction!) -> Void in
let url = NSURL(string: UIApplicationOpenSettingsURLString)!
UIApplication.sharedApplication().openURL(url)
})
]
showAlert("程序定位服务未开启", "您需要去设置界面启用我们App定位服务", actions, byVC: nil, nil)
default:
break
}
}
5.func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
if CLLocationManager.locationServicesEnabled() {
manager.delegate = self
manager.startUpdatingLocation()
if CLLocationManager.authorizationStatus() == preAuthorStatus && preAuthorStatus == .Denied
{
let actions = [
UIAlertAction(title: "关闭", style: .Cancel, handler: nil),
UIAlertAction(title: "前去设置", style: .Default, handler: { (action: UIAlertAction!) -> Void in
let url = NSURL(string: UIApplicationOpenSettingsURLString)!
UIApplication.sharedApplication().openURL(url)
})
]
showAlert("程序定位服务未开启", "您需要去设置界面启用我们App定位服务", actions, byVC: nil, nil)
}
}else {
manager.delegate = nil
manager.stopUpdatingLocation()
showAlert("定位服务无法使用,请开启手机定位服务.", nil, [UIAlertAction(title: "知道了", style: .Cancel, handler: nil)], byVC: nil, nil)
}
}
OK,收工
- iOS7.0以上 完整定位
- IOS7.0以上 电源、时间的状态栏取消设置方法
- UILabel的自适应高度iOS7.0以上版本
- ios7以上的二维码扫描
- iOS7及以上判断运营商
- ios7以上的二维码扫描
- ios7以上二维码的使用
- iOS7以上系统自定义UIAlertController
- 地理定位(iOS7)
- iOS 后台持续定位详解(支持ISO9.0以上)
- iOS7.0及以上图片转换成base64编码的方法(oc)
- 二维码扫描 IOS原生API IOS7.0及以上系统支持
- [iOS]毛玻璃在iOS8以上和iOS7以上的实现
- ios7以上版本隐藏/显示状态栏
- IOS7以上pushViewController界面卡顿问题
- iOS7以上使导航栏半透明
- iOS7以上隐藏、修改状态栏颜色
- ios7以上系统隐藏状态栏方法
- 广告真正出彩没想象中难
- SQLSERVER数据库的单引号
- PLSQL collection 示例 之 varray
- Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut
- 简单的实现考试功能
- iOS7.0以上 完整定位
- PHP 把时间转成几个小时前 几分钟前 几天前
- 2015.3.17旱冰场造价
- 分布式系统的事务处理深度分析
- 组合逻辑设计原理
- ios常见面试题,答案不一定准确 ,我会不断完善 答案,前十个答案是我自己写的
- xstream框架
- 通过软连接实现组管理员可读取该组用户的指定目录
- App Store审核指南 2015-03-17