From b41c3cc6bdebaa3bcaffdf65bc25f138b4be7523 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 28 Dec 2013 21:49:31 +0100 Subject: [PATCH] (iOS) Make apple_gamecontroller 'backwards compatible' with iOS 6 by doing runtime check for iOS version and then returning early --- apple/RetroArch_iOS.xcodeproj/project.pbxproj | 2 +- apple/common/apple_gamecontroller.m | 37 ++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/apple/RetroArch_iOS.xcodeproj/project.pbxproj b/apple/RetroArch_iOS.xcodeproj/project.pbxproj index 55c3cac0d4..39af7377d6 100644 --- a/apple/RetroArch_iOS.xcodeproj/project.pbxproj +++ b/apple/RetroArch_iOS.xcodeproj/project.pbxproj @@ -21,7 +21,7 @@ 96366C5516C9AC3300D64A22 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96366C5416C9AC3300D64A22 /* CoreAudio.framework */; }; 96366C5916C9ACF500D64A22 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96366C5816C9ACF500D64A22 /* AudioToolbox.framework */; }; 963C3C32186E3D2600A6EB1E /* apple_gamecontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 963C3C31186E3D2600A6EB1E /* apple_gamecontroller.m */; }; - 963C3C34186E3DED00A6EB1E /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963C3C33186E3DED00A6EB1E /* GameController.framework */; settings = {ATTRIBUTES = (Required, ); }; }; + 963C3C34186E3DED00A6EB1E /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963C3C33186E3DED00A6EB1E /* GameController.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 963F5AC816CC523B009BBD19 /* RAGameView.m in Sources */ = {isa = PBXBuildFile; fileRef = 963F5AC516CC523B009BBD19 /* RAGameView.m */; }; 9646869517BBBEAE00C5EA69 /* platform.m in Sources */ = {isa = PBXBuildFile; fileRef = 9646869417BBBEAE00C5EA69 /* platform.m */; }; 966B9CBD16E41E7A005B61E1 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 966B9CB816E41E7A005B61E1 /* Default-568h@2x.png */; }; diff --git a/apple/common/apple_gamecontroller.m b/apple/common/apple_gamecontroller.m index f107c2e747..c1679b9ba9 100644 --- a/apple/common/apple_gamecontroller.m +++ b/apple/common/apple_gamecontroller.m @@ -14,6 +14,10 @@ */ #include +#ifdef IOS +#include +static NSArray *versionCompatibility; +#endif #if defined(__IPHONE_7_0) && !defined(OSX) @@ -24,6 +28,10 @@ static void apple_gamecontroller_poll(GCController* controller) { +#ifdef IOS + if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + return; +#endif if (!controller || controller.playerIndex == MAX_PLAYERS) return; @@ -68,8 +76,12 @@ static void apple_gamecontroller_poll(GCController* controller) } } -void apple_gamecontroller_poll_all() +void apple_gamecontroller_poll_all(void) { +#ifdef IOS + if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + return; +#endif NSArray* controllers = [GCController controllers]; for (int i = 0; i != [controllers count]; i ++) @@ -78,6 +90,10 @@ void apple_gamecontroller_poll_all() void apple_gamecontroller_connect(GCController* controller) { +#ifdef IOS + if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + return; +#endif int32_t slot = apple_joypad_connect_gcapi(); controller.playerIndex = (slot >= 0 && slot < MAX_PLAYERS) ? slot : GCControllerPlayerIndexUnset; @@ -95,15 +111,26 @@ void apple_gamecontroller_connect(GCController* controller) void apple_gamecontroller_disconnect(GCController* controller) { +#ifdef IOS + if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + return; +#endif if (controller.playerIndex == GCControllerPlayerIndexUnset) return; apple_joypad_disconnect(controller.playerIndex); } -void apple_gamecontroller_init() +void apple_gamecontroller_init(void) { - [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification object:nil queue:[NSOperationQueue mainQueue] +#ifdef IOS + versionCompatibility = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; + + if ( [[versionCompatibility objectAtIndex:0] intValue] < 7 ) + return; +#endif + + [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { apple_gamecontroller_connect([note object]); } ]; [[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification object:nil queue:[NSOperationQueue mainQueue] @@ -112,12 +139,12 @@ void apple_gamecontroller_init() #else -void apple_gamecontroller_init() +void apple_gamecontroller_init(void) { } -void apple_gamecontroller_poll_all() +void apple_gamecontroller_poll_all(void) { }