APTimeZones 1.1

APTimeZones 1.1

测试测试
语言语言 Objective-CObjective C
许可证 MIT
发布最新版本2014年12月

Alterplay维护。



  • Serg Krivoblotsky

这是一个为iOS和OSX开发者提供,用于简化从给定CLLocation中提取NSTimeZone的实用工具。

您可以通过调用Google APIYahoo API来完成同样的工作,但APTimeZones在本地、离线且没有与托管解决方案相关的限制下运行。

使用方法

//Ukraine location
CLLocation *location = [[CLLocation alloc] initWithLatitude:50.449846
                                                  longitude:30.523629];

NSTimeZone *timeZone = [[APTimeZones sharedInstance] timeZoneWithLocation:location];
NSLog(@"%@", timeZone);

您可以使用APTimeZones与Apple CLGeocoder配合使用,以便接收给定城市字符串的NSTimeZone。

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"New York" completionHandler:^(NSArray *placemarks, NSError *error) {
    if (placemarks.count) {
        CLPlacemark *placemark = placemarks[0];
        CLLocation *location = placemark.location;

        NSString *countryCode = placemark.addressDictionary[@"CountryCode"];
        NSTimeZone *timeZone = [[APTimeZones sharedInstance] timeZoneWithLocation:location
                                                                      countryCode:countryCode];
        NSLog(@"%@", timeZone);
    } 
}];

版本1.1

我们使用1.1版本增加了实用分类,让时区的魔法更加简单。

CLLocation+APTimeZones

CLPlacemark+APTimeZones

使用方法

CLLocation *location = ...
NSLog(@"%@", location.timeZone);

CLPlacemark *placemark = ...;
NSLog(@"%@", placemark.timeZone);

另外,我们还添加了示例项目,展示了APTimeZones的使用方法 [YouTube上的演示视频]

githalytics.com alpha 如果您有任何改进意见或疑问,请随时提交一个issue并详细描述。

查看所有Alterplay的GitHub项目 通过邮件联系我们提出其他想法和项目。