mirror of https://github.com/LIJI32/SameBoy.git
Vibration support on legacy devices
This commit is contained in:
parent
ffc80b2c0d
commit
76500ebf15
|
@ -1,4 +1,5 @@
|
||||||
#import "GBHapticManager.h"
|
#import "GBHapticManager.h"
|
||||||
|
#import "GBHapticManagerLegacy.h"
|
||||||
#import <CoreHaptics/CoreHaptics.h>
|
#import <CoreHaptics/CoreHaptics.h>
|
||||||
|
|
||||||
@implementation GBHapticManager
|
@implementation GBHapticManager
|
||||||
|
@ -25,15 +26,14 @@
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (!self) return nil;
|
if (!self) return nil;
|
||||||
|
if (self.class != [GBHapticManager class]) return self;
|
||||||
|
|
||||||
if (@available(iOS 13.0, *)) {
|
if (@available(iOS 13.0, *)) {
|
||||||
_engine = [[CHHapticEngine alloc] initAndReturnError:nil];
|
_engine = [[CHHapticEngine alloc] initAndReturnError:nil];
|
||||||
_engine.playsHapticsOnly = true;
|
_engine.playsHapticsOnly = true;
|
||||||
_engine.autoShutdownEnabled = true;
|
_engine.autoShutdownEnabled = true;
|
||||||
}
|
}
|
||||||
else {
|
if (!_engine) return [[GBHapticManagerLegacy alloc] init];
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
if (!_engine) return nil;
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#import "GBHapticManager.h"
|
||||||
|
|
||||||
|
@interface GBHapticManagerLegacy : GBHapticManager
|
||||||
|
|
||||||
|
@end
|
|
@ -0,0 +1,27 @@
|
||||||
|
#import "GBHapticManagerLegacy.h"
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <AudioToolbox/AudioToolbox.h>
|
||||||
|
|
||||||
|
@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
|
Loading…
Reference in New Issue