Fixed building on iOS with MFI controllers disabled
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
diff --git a/src/joystick/iphoneos/SDL_sysjoystick.m b/src/joystick/iphoneos/SDL_sysjoystick.m
index 12657ff..4f413e9 100644
--- a/src/joystick/iphoneos/SDL_sysjoystick.m
+++ b/src/joystick/iphoneos/SDL_sysjoystick.m
@@ -393,8 +393,6 @@ static int
IOS_JoystickInit(void)
{
@autoreleasepool {
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
#if !TARGET_OS_TV
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
/* Default behavior, accelerometer as joystick */
@@ -417,6 +415,8 @@ IOS_JoystickInit(void)
SDL_AppleTVRemoteRotationHintChanged, NULL);
#endif /* TARGET_OS_TV */
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
connectObserver = [center addObserverForName:GCControllerDidConnectNotification
object:nil
queue:nil
@@ -466,17 +466,24 @@ IOS_JoystickGetDeviceName(int device_index)
static int
IOS_JoystickGetDevicePlayerIndex(int device_index)
{
+#ifdef SDL_JOYSTICK_MFI
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
- return device ? (int)device->controller.playerIndex : -1;
+ if (device && device->controller) {
+ return (int)device->controller.playerIndex;
+ }
+#endif
+ return -1;
}
static void
IOS_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
+#ifdef SDL_JOYSTICK_MFI
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
- if (device) {
+ if (device && device->controller) {
device->controller.playerIndex = player_index;
}
+#endif
}
static SDL_JoystickGUID