diff --git a/iOS/GBHapticManager.m b/iOS/GBHapticManager.m index 1a2a7ff..9cbc05b 100644 --- a/iOS/GBHapticManager.m +++ b/iOS/GBHapticManager.m @@ -1,4 +1,5 @@ #import "GBHapticManager.h" +#import "GBHapticManagerLegacy.h" #import @implementation GBHapticManager @@ -25,15 +26,14 @@ { self = [super init]; if (!self) return nil; + if (self.class != [GBHapticManager class]) return self; + if (@available(iOS 13.0, *)) { - _engine = [[CHHapticEngine alloc] initAndReturnError:nil]; - _engine.playsHapticsOnly = true; - _engine.autoShutdownEnabled = true; + _engine = [[CHHapticEngine alloc] initAndReturnError:nil]; + _engine.playsHapticsOnly = true; + _engine.autoShutdownEnabled = true; } - else { - return nil; - } - if (!_engine) return nil; + if (!_engine) return [[GBHapticManagerLegacy alloc] init]; return self; } diff --git a/iOS/GBHapticManagerLegacy.h b/iOS/GBHapticManagerLegacy.h new file mode 100644 index 0000000..1322d92 --- /dev/null +++ b/iOS/GBHapticManagerLegacy.h @@ -0,0 +1,5 @@ +#import "GBHapticManager.h" + +@interface GBHapticManagerLegacy : GBHapticManager + +@end diff --git a/iOS/GBHapticManagerLegacy.m b/iOS/GBHapticManagerLegacy.m new file mode 100644 index 0000000..43ce160 --- /dev/null +++ b/iOS/GBHapticManagerLegacy.m @@ -0,0 +1,27 @@ +#import "GBHapticManagerLegacy.h" +#import +#import + +@implementation GBHapticManagerLegacy + +- (void)doTapHaptic +{ + [[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium] impactOccurred]; +} + +- (void)setRumbleStrength:(double)rumble +{ + void AudioServicesStopSystemSound(SystemSoundID inSystemSoundID); + void AudioServicesPlaySystemSoundWithVibration(SystemSoundID inSystemSoundID, id arg, NSDictionary* vibratePattern); + if (rumble) { + AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, @{@"Intensity": @(rumble), + @"OffDuration": @0, + @"OnDuration": @100, + @"VibePattern": @[@YES, @1000], + }); + } + else { + AudioServicesStopSystemSound(kSystemSoundID_Vibrate); + } +} +@end