# [![INTULocationManager](https://github.com/intuit/LocationManager/blob/master/Images/INTULocationManager.png?raw=true)](#)
[![Build Status](http://img.shields.io/travis/intuit/LocationManager.svg?style=flat)](https://travis-ci.org/intuit/LocationManager) [![Test Coverage](http://img.shields.io/coveralls/intuit/LocationManager.svg?style=flat)](https://coveralls.io/r/intuit/LocationManager) [![Version](http://img.shields.io/cocoapods/v/INTULocationManager.svg?style=flat)](http://cocoapods.org/pods/INTULocationManager) [![Platform](http://img.shields.io/cocoapods/p/INTULocationManager.svg?style=flat)](http://cocoapods.org/pods/INTULocationManager) [![License](http://img.shields.io/cocoapods/l/INTULocationManager.svg?style=flat)](LICENSE)
INTULocationManager makes it easy to get the device's current location and heading on iOS. It is an Objective-C library that also works great in Swift.
INTULocationManager provides a block-based asynchronous API to request the current location, either once or continuously. It internally manages multiple simultaneous location and heading requests, and each one-time location request can specify its own desired accuracy level and timeout duration. INTULocationManager automatically starts location services when the first request comes in and stops location services as soon as all requests have been completed, all the while dynamically managing the power consumed by location services to reduce impact on battery life.
## What's wrong with CLLocationManager?
CLLocationManager requires you to manually detect and handle things like permissions, stale/inaccurate locations, errors, and more. CLLocationManager uses a more traditional delegate pattern instead of the modern block-based callback pattern. And while it works fine to track changes in the user's location over time (such as for turn-by-turn navigation), it is extremely cumbersome to correctly request a single location update (such as to determine the user's current city to get a weather forecast, or to autofill an address from the current location).
INTULocationManager makes it easy to request both the device's current location, either once or continuously, as well as the device's continuous heading. The API is extremely simple for both one-time location requests and recurring subscriptions to location updates. For one-time location requests, you can specify how accurate of a location you need, and how long you're willing to wait to get it. Significant location change monitoring is also supported. INTULocationManager is power efficient and conserves the device's battery by automatically determining and using the most efficient Core Location accuracy settings, and by automatically powering down location services (e.g. GPS or compass) as soon as they are no longer needed.
## Installation
*INTULocationManager requires iOS 6.0 or later.*
### Using [CocoaPods](http://cocoapods.org)
1. Add the pod `INTULocationManager` to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html).
```ruby
pod 'INTULocationManager'
```
1. Run `pod install` from Terminal, then open your app's `.xcworkspace` file to launch Xcode.
1. Import the `INTULocationManager.h` header.
* With `use_frameworks!` in your Podfile
* Swift: `import INTULocationManager`
* Objective-C: `#import <INTULocationManager/INTULocationManager.h>` (or with Modules enabled: `@import INTULocationManager;`)
* Without `use_frameworks!` in your Podfile
* Swift: Add `#import "INTULocationManager.h"` to your bridging header.
* Objective-C: `#import "INTULocationManager.h"`
### Using [Carthage](https://github.com/Carthage/Carthage)
1. Add the `intuit/LocationManager` project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile).
```ogdl
github "intuit/LocationManager"
```
1. Run `carthage update`, then follow the [additional steps required](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to add the iOS and/or Mac frameworks into your project.
1. Import the INTULocationManager framework/module.
* Swift: `import INTULocationManager`
* Objective-C: `#import <INTULocationManager/INTULocationManager.h>` (or with Modules enabled: `@import INTULocationManager;`)
### Manually from GitHub
1. Download all the files in the [INTULocationManager subdirectory](LocationManager/INTULocationManager).
1. Add the source files to your Xcode project (drag and drop is easiest).
1. Import the `INTULocationManager.h` header.
* Swift: Add `#import "INTULocationManager.h"` to your bridging header.
* Objective-C: `#import "INTULocationManager.h"`
## Usage
### Requesting Permission to Access Location Services
INTULocationManager automatically handles obtaining permission to access location services when you issue a location request and the user has not already granted your app permission to access location services.
#### iOS 6 & 7
For iOS 6 & 7, it is recommended that you provide a description for how your app uses location services by setting a string for the key [`NSLocationUsageDescription`](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW27) in your app's `Info.plist` file.
#### iOS 8
Starting with iOS 8, you **must** provide a description for how your app uses location services by setting a string for the key [`NSLocationWhenInUseUsageDescription`](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW26) or [`NSLocationAlwaysUsageDescription`](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW18) in your app's `Info.plist` file. INTULocationManager determines which level of permissions to request based on which description key is present. You should only request the minimum permission level that your app requires, therefore it is recommended that you use the "When In Use" level unless you require more access. If you provide values for both description keys, the more permissive "Always" level is requested.
### Getting the Current Location (once)
To get the device's current location, use the method `requestLocationWithDesiredAccuracy:timeout:block:`.
The `desiredAccuracy` parameter specifies how **accurate and recent** of a location you need. The possible values are:
```objective-c
INTULocationAccuracyCity // 5000 meters or better, received within the last 10 minutes -- lowest accuracy
INTULocationAccuracyNeighborhood // 1000 meters or better, received within the last 5 minutes
INTULocationAccuracyBlock // 100 meters or better, received within the last 1 minute
INTULocationAccuracyHouse // 15 meters or better, received within the last 15 seconds
INTULocationAccuracyRoom // 5 meters or better, received within the last 5 seconds -- highest accuracy
```
The `timeout` parameter specifies how long you are willing to wait for a location with the accuracy you requested. The timeout guarantees that your block will execute within this period of time, either with a location of at least the accuracy you requested (`INTULocationStatusSuccess`), or with whatever location could be determined before the timeout interval was up (`INTULocationStatusTimedOut`). Pass `0.0` for no timeout *(not recommended)*.
By default, the timeout countdown begins as soon as the `requestLocationWithDesiredAccuracy:timeout:block:` method is called. However, there is another variant of this method that includes a `delayUntilAuthorized:` parameter, which allows you to pass `YES` to delay the start of the timeout countdown until the user has responded to the system location services permissions prompt (if the user hasn't allowed or denied the app access yet).
Here's an example:
```objective-c
INTULocationMana
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
选择城市.zip (65个子文件)
选择城市
CitysViewController.m 13KB
INTULocationManager
LICENSE 1KB
.DS_Store 6KB
LocationManager
INTULocationManager
INTULocationManager.m 44KB
INTULocationManager.h 9KB
INTURequestIDGenerator.m 1KB
INTULocationRequest.h 4KB
INTULocationRequest.m 7KB
INTULocationManager+Internal.h 1KB
INTURequestIDGenerator.h 1KB
INTUHeadingRequest.h 2KB
INTULocationRequestDefines.h 9KB
INTUHeadingRequest.m 2KB
README.md 18KB
UIButton+Submitting.h 794B
UIButton+Block.m 691B
CitysXMLParser.m 773B
.DS_Store 6KB
CityModel.m 206B
CitysXMLParser.h 365B
CitysViewController.h 266B
CityModel.h 439B
GTFixHeader.h 2KB
NSDictionary
NSDictionary+JKSafeAccess.m 8KB
NSDictionaryHeader.h 372B
NSDictionary+MAC.h 740B
NSDictionary+JKMerge.h 884B
NSDictionary+JKBlock.h 559B
NSDictionary+MAC.m 3KB
NSDictionary+JKSafeAccess.h 2KB
NSDictionary+JKMerge.m 2KB
XMLDictionary
XMLDictionary.h 4KB
XMLDictionary.m 15KB
NSDictionary+JKBlock.m 2KB
NSObject
citys.xml 35KB
UIButton+Submitting.m 3KB
UIButton+Block.h 278B
NSString
NSString+Emoji.m 49KB
NSString+UUID.h 438B
NSString+Trims.h 677B
NSString+MacRegexCategory.m 14KB
NSString+MAC.m 4KB
NSString+Trims.m 2KB
HanZiToPingYin(汉字转成拼音)
NSString+HLHanZiToPinYin.m 1KB
NSString+HLHanZiToPinYin.h 465B
MF_Base64Additions.h 1KB
NSString+RemoveEmoji.h 499B
NSString+MacRegexCategory.h 6KB
NSString+MAC.h 1KB
MF_Base64Additions.m 11KB
NSString+UUID.m 895B
NSString+Emoji.h 1KB
NSString+MIME.h 539B
NSString+RemoveEmoji.m 3KB
NSString+MIME.m 12KB
Pinyin
ChineseToPinyin.h 184B
ChineseToPinyin.m 103KB
NSStringHeader.h 466B
SearchCore
SearchCore.mm 114KB
SearchCoreManager.h 3KB
Array.h 2KB
SearchCore.h 7KB
multipy_unicode.dat 8KB
SearchCoreManager.mm 10KB
Array.mm 4KB
共 65 条
- 1
资源评论
kuuailetianzi
- 粉丝: 6
- 资源: 56
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功