From 2c53d57e9ef64968b1cbb4df253e4ddbfe0762b1 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 13 Apr 2015 18:17:48 +0200 Subject: [PATCH] (iOS) Refactor get_ios_version_major --- apple/iOS/browser.m | 17 ++++++++++++++--- apple/iOS/platform.h | 2 +- apple/iOS/platform.m | 19 +++++++++++-------- input/drivers_hid/mfi_hid.m | 8 ++++++-- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index 1f1bff189b..50ae6c6f78 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -337,10 +337,15 @@ static void file_action(enum file_action action, NSString* source, NSString* tar if (idx_path) { + int major, minor; bool is_zip; UIActionSheet *menu; - NSString *button4_name = (get_ios_version_major() >= 7) ? BOXSTRING("AirDrop") : BOXSTRING("Delete"); - NSString *button5_name = (get_ios_version_major() >= 7) ? BOXSTRING("Delete") : nil; + NSString *button4_name, *button5_name; + + get_ios_version_major(&major, &minor); + + button4_name = (major >= 7) ? BOXSTRING("AirDrop") : BOXSTRING("Delete"); + button5_name = (major >= 7) ? BOXSTRING("Delete") : nil; self.selectedItem = [self itemForIndexPath:idx_path]; is_zip = !(strcmp(self.selectedItem.path.pathExtension.UTF8String, "zip")); @@ -357,8 +362,14 @@ static void file_action(enum file_action action, NSString* source, NSString* tar /* Called by the action sheet created in (void)fileAction: */ - (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { + int major, minor; NSString* target = self.selectedItem.path; NSString* action = [actionSheet buttonTitleAtIndex:buttonIndex]; + + get_ios_version_major(&major, &minor); + + (void)major; + (void)minor; if (!strcmp(action.UTF8String, "Unzip")) { @@ -382,7 +393,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar [alertView show]; } #ifdef __IPHONE_7_0 - else if (!strcmp(action.UTF8String, "AirDrop") && (get_ios_version_major() >= 7)) + else if (!strcmp(action.UTF8String, "AirDrop") && (major >= 7)) { /* TODO: ZIP if not already zipped. */ NSURL *url = [NSURL fileURLWithPath:self.selectedItem.path isDirectory:self.selectedItem.isDirectory]; diff --git a/apple/iOS/platform.h b/apple/iOS/platform.h index a3702fffe0..74e344e7fc 100644 --- a/apple/iOS/platform.h +++ b/apple/iOS/platform.h @@ -49,6 +49,6 @@ extern apple_frontend_settings_t apple_frontend_settings; - (void)refreshSystemConfig; @end -int get_ios_version_major(void); +void get_ios_version_major(int *major, int *minor); #endif diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index 0d7048f69d..fa538844a9 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -68,14 +68,14 @@ void apple_rarch_exited(void) apple_frontend_settings_t apple_frontend_settings; -int get_ios_version_major(void) +void get_ios_version_major(int *major, int *minor) { - static int version = -1; - - if (version < 0) - version = (int)[[[UIDevice currentDevice] systemVersion] floatValue]; - - return version; + NSArray *decomposed_os_version = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; + + if (major && decomposed_os_version.count > 0) + *major = [decomposed_os_version[0] integerValue]; + if (minor && decomposed_os_version.count > 1) + *minor = [decomposed_os_version[1] integerValue]; } extern float apple_gfx_ctx_get_native_scale(void); @@ -200,12 +200,15 @@ enum - (void)sendEvent:(UIEvent *)event { + int major, minor; [super sendEvent:event]; if (event.allTouches.count) handle_touch_event(event.allTouches.allObjects); - if (!(get_ios_version_major() >= 7) && [event respondsToSelector:@selector(_gsEvent)]) + get_ios_version_major(&major, &minor); + + if (!(major >= 7) && [event respondsToSelector:@selector(_gsEvent)]) { // Stolen from: http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html const uint8_t *eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]); diff --git a/input/drivers_hid/mfi_hid.m b/input/drivers_hid/mfi_hid.m index 2103eebf72..db62ade853 100644 --- a/input/drivers_hid/mfi_hid.m +++ b/input/drivers_hid/mfi_hid.m @@ -15,6 +15,7 @@ #include #import +#include #include "mfi_hid.h" #include "../../input/drivers/apple_input.h" @@ -23,9 +24,12 @@ enum GCCONTROLLER_PLAYER_INDEX_UNSET = -1, }; -static BOOL apple_gamecontroller_available(void) +static bool apple_gamecontroller_available(void) { - if (get_ios_version_major() <= 6) + int major, minor; + get_ios_version_major(&major, &minor); + + if (major <= 6) return false; /* by checking for extern symbols defined by the framework, we can check for its * existence at runtime. This is the Apple endorsed way of dealing with this */