[ios] Fixed version check.

This commit is contained in:
Ilya Grechuhin 2015-06-03 18:46:31 +03:00 committed by Alex Zolotarev
parent a1d2027f4a
commit f09f8296bb
12 changed files with 42 additions and 41 deletions

View file

@ -31,7 +31,25 @@ static inline NSString * const kApplicationGroupIdentifier()
return developerGroupIdentifier;
}
static inline BOOL isIOSVersionLessThan(NSInteger version)
static inline BOOL firstVersionIsLessThanSecond(NSString * first, NSString * second)
{
return [UIDevice currentDevice].systemName.integerValue < version;
}
NSArray const * const f = [first componentsSeparatedByString:@"."];
NSArray const * const s = [second componentsSeparatedByString:@"."];
NSUInteger iter = 0;
while (f.count > iter && s.count > iter)
{
NSInteger fiv = ((NSString *)f[iter]).integerValue;
NSInteger siv = ((NSString *)s[iter]).integerValue;
if (fiv == siv)
iter++;
else
return fiv < siv;
}
return f.count < s.count;
}
static inline BOOL isIOSVersionLessThan(NSString * version)
{
return firstVersionIsLessThanSecond([UIDevice currentDevice].systemVersion, version);
}

View file

@ -8,6 +8,7 @@
#import "MWMAlertViewController.h"
#import "MWMDownloadTransitMapAlert.h"
#import "Common.h"
static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController";
@ -32,7 +33,7 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController
{
[super viewDidLoad];
// Need only for iOS 5.
if (isIOSVersionLessThan(6))
if (isIOSVersionLessThan(@"6"))
self.tap.delegate = self;
}

View file

@ -201,7 +201,7 @@
- (double)correctContentScale
{
UIScreen * uiScreen = [UIScreen mainScreen];
if (SYSTEM_VERSION_IS_LESS_THAN(@"8"))
if (isIOSVersionLessThan(@"8"))
return uiScreen.scale;
else
return uiScreen.nativeScale;

View file

@ -106,7 +106,7 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
UIImage * shareImage = [UIImage imageNamed:notificationInfo[@"NotifiicationShareImage"]];
LocalNotificationInfoProvider * infoProvider = [[LocalNotificationInfoProvider alloc] initWithDictionary:notificationInfo];
if (SYSTEM_VERSION_IS_LESS_THAN(@"6.0"))
if (isIOSVersionLessThan(@"6.0"))
{
UIPasteboard * pasteboard = [UIPasteboard generalPasteboard];
pasteboard.URL = link;
@ -122,7 +122,7 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
UIActivityViewController * activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
NSMutableArray * excludedActivityTypes = [@[UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll] mutableCopy];
if (!SYSTEM_VERSION_IS_LESS_THAN(@"7.0"))
if (!isIOSVersionLessThan(@"7.0"))
[excludedActivityTypes addObject:UIActivityTypeAirDrop];
activityVC.excludedActivityTypes = excludedActivityTypes;
UIWindow * window = [[UIApplication sharedApplication].windows firstObject];

View file

@ -173,9 +173,8 @@
self.separatorBottom.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleTopMargin;
// On iOS6 and lower table view looks different, we won't show separators there.
if (SYSTEM_VERSION_IS_LESS_THAN(@"7.0")) {
if (isIOSVersionLessThan(@"7.0"))
self.separatorTop.alpha = self.separator.alpha = self.separatorBottom.alpha = 0.0;
}
}
- (void)prepareForReuse

View file

@ -741,7 +741,7 @@ typedef NS_ENUM(NSUInteger, ForceRoutingStateChange)
{
NSString * title;
NSString * message;
if (isIOSVersionLessThan(7))
if (isIOSVersionLessThan(@"7"))
message = L(@"routing_disclaimer");
else
title = L(@"routing_disclaimer");
@ -855,7 +855,7 @@ typedef NS_ENUM(NSUInteger, ForceRoutingStateChange)
{
if (!_apiBar)
{
UIImage * image = SYSTEM_VERSION_IS_LESS_THAN(@"7") ? [UIImage imageNamed:@"ApiBarBackground6"] : [UIImage imageNamed:@"ApiBarBackground7"];
UIImage * image = isIOSVersionLessThan(@"7") ? [UIImage imageNamed:@"ApiBarBackground6"] : [UIImage imageNamed:@"ApiBarBackground7"];
_apiBar = [[UIImageView alloc] initWithImage:[image resizableImageWithCapInsets:UIEdgeInsetsZero]];
_apiBar.width = self.view.width;
_apiBar.userInteractionEnabled = YES;

View file

@ -213,7 +213,7 @@ void InitLocalizedStrings()
application.applicationIconBadgeNumber = f.GetCountryTree().GetActiveMapLayout().GetOutOfDateCount();
f.GetLocationState()->InvalidatePosition();
if (isIOSVersionLessThan(7))
if (isIOSVersionLessThan(@"7"))
return [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey] != nil;
return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
@ -301,7 +301,7 @@ void InitLocalizedStrings()
m_mwmURL = nil;
m_fileURL = nil;
if (!isIOSVersionLessThan(7))
if (!isIOSVersionLessThan(@"7"))
[FBSDKAppEvents activateApp];
[self restoreRouteState];
@ -348,7 +348,7 @@ void InitLocalizedStrings()
attributes[UITextAttributeTextShadowColor] = [UIColor clearColor];
[[UINavigationBar appearanceWhenContainedIn:[NavigationController class], nil] setTintColor:[UIColor colorWithColorCode:@"15c584"]];
if (!SYSTEM_VERSION_IS_LESS_THAN(@"7"))
if (!isIOSVersionLessThan(@"7"))
{
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
@ -376,7 +376,7 @@ void InitLocalizedStrings()
if ([self checkLaunchURL:url])
return YES;
if (isIOSVersionLessThan(7))
if (isIOSVersionLessThan(@"7"))
return NO;
return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
@ -476,7 +476,7 @@ void InitLocalizedStrings()
- (void)trackWatchUser
{
if (isIOSVersionLessThan(8))
if (isIOSVersionLessThan(@"8"))
return;
NSUserDefaults *standartDefaults = [NSUserDefaults standardUserDefaults];
@ -545,7 +545,7 @@ void InitLocalizedStrings()
- (void)showFacebookAlert
{
if (isIOSVersionLessThan(7) || !Reachability.reachabilityForInternetConnection.isReachable)
if (isIOSVersionLessThan(@"7") || !Reachability.reachabilityForInternetConnection.isReachable)
return;
UIViewController *topViewController = [(UINavigationController*)m_window.rootViewController visibleViewController];
@ -632,27 +632,12 @@ void InitLocalizedStrings()
{
NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
NSString *firstVersion = [[NSUserDefaults standardUserDefaults] stringForKey:kUDFirstVersionKey];
if (!firstVersion.length || [self version:currentVersion greaterThanVersion:firstVersion])
if (!firstVersion.length || firstVersionIsLessThanSecond(firstVersion, currentVersion))
return NO;
return YES;
}
- (BOOL)version:(NSString *)first greaterThanVersion:(NSString *)second
{
NSArray *f = [first componentsSeparatedByString:@"."];
NSArray *s = [second componentsSeparatedByString:@"."];
NSUInteger iter = 0;
while (f.count > iter && s.count > iter)
{
if ([(NSString*)f[iter] integerValue] == [(NSString*)s[iter] integerValue])
iter++;
else
return [(NSString*)f[iter] integerValue] > [(NSString*)s[iter] integerValue];
}
return f.count > s.count;
}
+ (NSInteger)daysBetweenNowAndDate:(NSDate*)fromDate
{
if (!fromDate)

View file

@ -472,7 +472,7 @@ typedef NS_ENUM(NSUInteger, CellRow)
- (CGFloat)viewMinY
{
return self.statusBarIncluded ? (SYSTEM_VERSION_IS_LESS_THAN(@"7") ? -20 : 0) : -20;
return self.statusBarIncluded ? (isIOSVersionLessThan(@"7") ? -20 : 0) : -20;
}
- (CGFloat)arrowMinYForHeaderWithHeight:(CGFloat)headerHeight
@ -1183,7 +1183,7 @@ typedef NS_ENUM(NSUInteger, CellRow)
_headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
if (SYSTEM_VERSION_IS_LESS_THAN(@"6"))
if (isIOSVersionLessThan(@"6"))
{
UIView * touchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _headerView.width - 64, _headerView.height)];
[_headerView addSubview:touchView];

View file

@ -190,7 +190,7 @@ extern NSString * const kAlohalyticsTapEventKey;
- (CGFloat)viewMinY
{
return SYSTEM_VERSION_IS_LESS_THAN(@"7") ? -20 : 0;
return isIOSVersionLessThan(@"7") ? -20 : 0;
}
- (UIView *)phoneIdiomView

View file

@ -503,12 +503,12 @@ static void onSearchResultCallback(search::Results const & results)
- (CGFloat)defaultSearchBarMinY
{
return SYSTEM_VERSION_IS_LESS_THAN(@"7") ? 3 : 20;
return isIOSVersionLessThan(@"7") ? 3 : 20;
}
- (CGFloat)defaultTopBackgroundHeight
{
return SYSTEM_VERSION_IS_LESS_THAN(@"7") ? 44 : 64;
return isIOSVersionLessThan(@"7") ? 44 : 64;
}
- (BOOL)iPhoneInLandscape

View file

@ -11,7 +11,7 @@
[backButton setImage:[UIImage imageNamed:@"NavigationBarBackButton"] forState:UIControlStateNormal];
UIBarButtonItem * space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
space.width = SYSTEM_VERSION_IS_LESS_THAN(@"7") ? -8 : -16;
space.width = isIOSVersionLessThan(@"7") ? -8 : -16;
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItems = @[space, item];
}

View file

@ -8,8 +8,6 @@
#define IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define SYSTEM_VERSION_IS_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define L(str) NSLocalizedString(str, nil)
#define INTEGRAL(f) ([UIScreen mainScreen].scale == 1 ? floor(f) : f)