TimeZoneLocate
此实用程序是支持捆绑框架的 APTimeZones 库的 Swift 版本。如果您的项目是 Objective-C,我们建议您使用他们的库。
- 对于 Swift 5 版本,使用版本
~> 0.5.0
。 - 对于 Swift 4 版本,使用版本
~> 0.4.0
。 - 对于 Swift 3 版本,使用版本
~> 0.3.0
。 - 对于 Swift 2 版本,使用版本
~> 0.1.0
。
使用方法
//San Diego, CA, USA
let location = CLLocation(latitude: 32.88, longitude: -117.15)
//TimeZone from extension (fast, synchronous, approximate)
var timeZone = location.timeZone
print(timeZone)
//or calling the class method
timeZone = TimeZoneLocate.timeZone(location: location)
print(timeZone)
//if you have the country code, you can speed things up.
timeZone = TimeZoneLocate.timeZone(location: location, countryCode: "US")
// A MORE accurate time zone if you are connected to network. (iOS 9.0 or later)
location.timeZone { (tz) -> (Void) in
guard let tz = tz else { return }
// got a more accureate timezone from the network
print("Network TimeZone: \(tz.identifier)")
}
// Same thing
TimeZoneLocate.geocodeTimeZone(location: location) { (tz) -> (Void) in
guard let tz = tz else { return }
print("Network TimeZone: \(tz.identifier) (class method)")
}
安装
要安装它,只需将以下行添加到您的 Podfile 中
pod "TimeZoneLocate"
作者
- 原始 Objective-C 版本:Sergii Kryvoblotskyi, Alterplay
- Swift 贡献者:Anthony Persaud,[email protected] (https://www.modernistik.com)
许可证
TimeZoneLocate 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。