iOS7.0以上 完整定位

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,收工

时间: 2024-09-20 18:47:16

iOS7.0以上 完整定位的相关文章

探索Oracle之数据库升级二 11.2.0.3升级到11.2.0.4完整步骤

探索Oracle之数据库升级二  11.2.0.3升级到11.2.0.4完整步骤 说明:         这篇文章主要是记录下单实例环境下Oracle 11.2.0.1升级到11.2.0.3的过程,当然RAC的升级是会有所不同.但是他们每个版本之间升级步骤都是差不多的,先升级Database Software,再升级Oracle Instance. Oracle 11.2.0.4的Patchset No:19852360下载需要有Oracle Support才可以.  Patchset包含有7个

IOS7.0 UILabel实现自适应高度的新方法

//IOS7.0中利用- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context 方法可以获取label的Size大小,来自适应高度,取代了之前的- (CGSize)sizeWithFont:(UIFont *)font const

ios7.0结合storyborad实现页面跳转的总结

折腾了一整天,本文总结一下ios7.0页面跳转有关的内容 storyboard的潜规则 我接触ios很晚,环境已经是xcode5+ios7,所以对以前的IOS开发模式并不了解.在网上查阅了很多资料,发现以前的代码,很多都需要自己coding来创建ViewController,比如: Objc代码   WTwoViewController *controller = [[WTwoViewController alloc]initWithNibName:@"WTwoViewController&qu

iOS开发之iOS6.0\iOS7.0\iOS8.0的UIAlertView message 文字对齐设置

是不是发现原来这段代码: #pragma mark - #pragma mark - alert delegate - (void) willPresentAlertView:(UIAlertView *)alertView { for (UIView *subViewin alertView.subviews) { UILabel *tmpLabel = (UILabel *)subView; tmpLabel.textAlignment =NSTextAlignmentLeft; } } 在

解决 ios7.0 以后自定义导航栏左边按钮靠右的问题

解决 ios7.0 以后自定义导航栏左边按钮靠右的问题 www.111cn.net 编辑:edit02_lz 来源:转载 最近开发了一个ios的app,在ios7.0+出现自定义导航栏左边按钮出现靠右的情况,后来自己解决了,解决办法如下 1.自定义按钮  代码如下 复制代码 //左按钮UIButton *leftBtn = [[UIButton alloc]initWithFrame:RectWithPara(-20, 0, 44, 44)];[leftBtn addTarget:self ac

App Icon and Launch Images for iOS7.0 or Later

App Icon and Launch Images for iOS7.0 or Later 1.App Icon File Name File Size(px) Used For [email protected] 58 x 58 Spotlight and Settings on devices with retina display [email protected] 87 x 87 Settings on iPhone 6 Plus [email protected] 80 x 80 S

.NET Core 2.0 获取完整的URL

原文:.NET Core 2.0 获取完整的URL 在之前的ASP.NET中,可以通过 Request.Url.AbsoluteUri 获取,但在ASP.NET Core没有这个实现,请问如何获取呢? 方法一:先引用“using Microsoft.AspNetCore.Http.Extensions;”,然后直接用“Request.GetDisplayUrl();” 方法二:后来参考 Microsoft.AspNetCore.Rewrite 的源代码,写了一个扩展方法实现了. namespac

iOS iOS9.0 的CoreLocation定位

一.简介 iOS9.0如果当前处于前台授权状态,默认是不可以后台获取用户位置. 如果在前台授权下,让其能获取到后台定位,该怎么办 可以设置以下属性为YES,就可以继续获取后台位置,但是会出现蓝条 使用注意:必须设置对应的后台模式,勾选后台模式:location updates @property(assign,nonatomic) BOOL allowsBackgroundLocationUpdates 注意:iOS9.0 可以单次请求用户位置 - (void)requestLocation /

Android 6.0一个完整的native service

 上一篇博客<Android 6.0 如何添加完整的系统服务(app-framework-kernel)>http://www.cnblogs.com/hackfun/p/7418902.html介绍了如何添加一个系统服务,客户端和服务端都是基于JAVA实现的OpersysService.经过进一步的学习,我将演示如何使用C++实现一个相同功能的系统服务hfnativeservice.为了兼容OpersysService,将保留Opersys-Service服务端中的HAL和driver,供h