From eeff9b74dae91938804152aa19d64f36121d2592 Mon Sep 17 00:00:00 2001 From: Rex Xiong Date: Sat, 27 Sep 2025 13:13:26 -0700 Subject: [PATCH 1/2] Fallback to phone haptics engine if controller doesn't support it --- VoidLink/Input/HapticContext.m | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/VoidLink/Input/HapticContext.m b/VoidLink/Input/HapticContext.m index b61124cc..6089dd4a 100644 --- a/VoidLink/Input/HapticContext.m +++ b/VoidLink/Input/HapticContext.m @@ -84,18 +84,32 @@ } -(id) initWithGamepad:(GCController*)gamepad locality:(GCHapticsLocality)locality API_AVAILABLE(ios(14.0), tvos(14.0)) { + bool needFallBackToPhoneHaptics = false; + if (gamepad.haptics == nil) { Log(LOG_W, @"Controller %d does not support haptics", gamepad.playerIndex); - return nil; + needFallBackToPhoneHaptics = true; + } + else if (![[gamepad.haptics supportedLocalities] containsObject:locality]) { + Log(LOG_W, @"Controller %d does not support haptic locality: %@", gamepad.playerIndex, locality); + needFallBackToPhoneHaptics = true; } - if (![[gamepad.haptics supportedLocalities] containsObject:locality]) { - Log(LOG_W, @"Controller %d does not support haptic locality: %@", gamepad.playerIndex, locality); - return nil; + if (needFallBackToPhoneHaptics) { + if (@available(iOS 13.0, *)) { + Log(LOG_W, @"Controller %d falls back to use iPhone Haptics for locality: %@", gamepad.playerIndex, locality); + NSError *error = nil; + _hapticEngine = [[CHHapticEngine alloc] initAndReturnError:&error]; + } + else { + return nil; + } + } + else { + _hapticEngine = [gamepad.haptics createEngineWithLocality:locality]; } _playerIndex = gamepad.playerIndex; - _hapticEngine = [gamepad.haptics createEngineWithLocality:locality]; NSError* error; [_hapticEngine startAndReturnError:&error]; From 87d9590f3ba2075f9813ed2a238fdec0c8a07c85 Mon Sep 17 00:00:00 2001 From: Rex Xiong Date: Sat, 27 Sep 2025 13:35:19 -0700 Subject: [PATCH 2/2] Update HapticContext.m --- VoidLink/Input/HapticContext.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/VoidLink/Input/HapticContext.m b/VoidLink/Input/HapticContext.m index 6089dd4a..07749fe9 100644 --- a/VoidLink/Input/HapticContext.m +++ b/VoidLink/Input/HapticContext.m @@ -100,6 +100,10 @@ Log(LOG_W, @"Controller %d falls back to use iPhone Haptics for locality: %@", gamepad.playerIndex, locality); NSError *error = nil; _hapticEngine = [[CHHapticEngine alloc] initAndReturnError:&error]; + if (error != nil) { + Log(LOG_W, @"Controller %d: iPhone Haptic engine failed to start: %@", gamepad.playerIndex, error); + return nil; + } } else { return nil;