iOS - [CLPlacemark timeZone]: 无法识别的选择器 iOS 8
iOS - [CLPlacemark timeZone]: unrecognized selector iOS 8
我正在使用此方法从 lat/long
获取 timeZone
。
-(void)getTimeZoneFromLatLong
{
CLLocation *location = [[CLLocation alloc] initWithLatitude:self.parentVC.currentCity.latitude.doubleValue longitude:self.parentVC.currentCity.longitude.doubleValue];
CLGeocoder *geoCoder = [[CLGeocoder alloc]init];
[geoCoder reverseGeocodeLocation: location completionHandler:^(NSArray *placemarks, NSError *error)
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
_placemark = placemark;
}];
}
然后我可以使用 timeZone
来调用 :
EDSunriseSet *eds = [EDSunriseSet sunrisesetWithTimezone:_placemark.timeZone
latitude:latitude.doubleValue longitude:longitude.doubleValue];
EDSunriseSet
是一个库,用于从 lat/long
和 timeZone
.
中获取 Sunrise/Sunset
值
它运行完美,但是 Crashlytics
提醒我 [CLPlacemark timeZone]
与 iOS8
及更低版本不兼容。
如何调整我的代码以适应 iOS8
?
编辑: [_placemark timezone]
和 _placemark.timezone
都被接受了?
可从 iOS 9.
/*
* timeZone
*
* Discussion:
* Returns the time zone associated with the placemark.
*/
@available(iOS 9.0, *)
open var timeZone: TimeZone? { get }
对于iOS8,试试这个
CLLocation *currentLocaiton = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
[geoCoder reverseGeocodeLocation:currentLocaiton completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {placeMark = [placemarks lastObject];
NSRegularExpression regex = [NSRegularExpression regularExpressionWithPattern:@"identifier = \"[a-z]*\/[a-z]_*[a-z]*\"" options:NSRegularExpressionCaseInsensitive error:NULL];
NSTextCheckingResult *newSearchString = [regex firstMatchInString:[placeMark description] options:0 range:NSMakeRange(0, [placeMark.description length])];
NSString *substr = [placeMark.description substringWithRange:newSearchString.range]; NSLog(@"timezone %@",substr);
}
我正在使用此方法从 lat/long
获取 timeZone
。
-(void)getTimeZoneFromLatLong
{
CLLocation *location = [[CLLocation alloc] initWithLatitude:self.parentVC.currentCity.latitude.doubleValue longitude:self.parentVC.currentCity.longitude.doubleValue];
CLGeocoder *geoCoder = [[CLGeocoder alloc]init];
[geoCoder reverseGeocodeLocation: location completionHandler:^(NSArray *placemarks, NSError *error)
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
_placemark = placemark;
}];
}
然后我可以使用 timeZone
来调用 :
EDSunriseSet *eds = [EDSunriseSet sunrisesetWithTimezone:_placemark.timeZone
latitude:latitude.doubleValue longitude:longitude.doubleValue];
EDSunriseSet
是一个库,用于从 lat/long
和 timeZone
.
Sunrise/Sunset
值
它运行完美,但是 Crashlytics
提醒我 [CLPlacemark timeZone]
与 iOS8
及更低版本不兼容。
如何调整我的代码以适应 iOS8
?
编辑: [_placemark timezone]
和 _placemark.timezone
都被接受了?
可从 iOS 9.
/*
* timeZone
*
* Discussion:
* Returns the time zone associated with the placemark.
*/
@available(iOS 9.0, *)
open var timeZone: TimeZone? { get }
对于iOS8,试试这个
CLLocation *currentLocaiton = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
[geoCoder reverseGeocodeLocation:currentLocaiton completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {placeMark = [placemarks lastObject];
NSRegularExpression regex = [NSRegularExpression regularExpressionWithPattern:@"identifier = \"[a-z]*\/[a-z]_*[a-z]*\"" options:NSRegularExpressionCaseInsensitive error:NULL];
NSTextCheckingResult *newSearchString = [regex firstMatchInString:[placeMark description] options:0 range:NSMakeRange(0, [placeMark.description length])];
NSString *substr = [placeMark.description substringWithRange:newSearchString.range]; NSLog(@"timezone %@",substr);
}