这是一个用于简单阻塞获取 iOS 用户当前位置的实用类。此类在简洁的 Objective-C 接口下封装了 CLLocationManager
。
FTLocationManager
源代码FTLocationManager
文件夹中的文件添加到您的项目中 (FTLocationManager.h
/.m
)CoreLocation.framework
// Get FTLocationManager singleton instance
FTLocationManager *locationManager = [FTLocationManager sharedManager];
// Ask the location manager to get current location and get notified using provided handler block
[locationManager updateLocationWithCompletionHandler:^(CLLocation *location, NSError *error, BOOL locationServicesDisabled) {
if (error)
{
// Handle error here
if (locationServicesDisabled) {
// Location services are disabled, you can ask the user to enable them for example
}
}
else
{
// Do whatever you want with the current user's location
}
}];
完成!
您可以使用一些属性来自定义 FTLocationManager
的行为,但通常不需要这样做,因为它使用合理的默认值。
管理器会自动跳过一些最初接收到的错误,以真正获取一些位置。
默认值:3个错误(当内部 CLLocationManager
返回第三个错误时,将调用错误处理块)
管理器会自动使用超时以确保在请求位置后的某合理时间内确实会调用处理程序块。
默认值:3秒(如果内部的 CLLocationManager
在调用 updateLocationWithCompletionHandler:
后 3 秒内没有给出任何位置,则处理程序块会使用自定义错误和带有 FTLocationManagerErrorDomain
域和 FTLocationManagerErrorCodeTimedOut
状态码的错误)
FTLocationManager
使用 CLLocationManager
并将其封装在非常简单的基于块的接口下面。请参阅示例项目和源代码以获取有关实现细节的详细信息。
在 iOS 5.0+ 上进行了测试,支持 ARC
FTCoreText 由 FuerteInt 开发。请给我们发送电子邮件,告诉我们您是如何使用此组件的。
The MIT License (MIT) Copyright (c) 2013 Fuerte International Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.