From 1f7e7e28161bfcfeb778c3a70ddbe4d66a80ad01 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 11 Nov 2021 02:28:02 +0900 Subject: [PATCH] internal/uidriver/mobile: Remove the warnings Closes #1872 --- internal/uidriver/mobile/vibrate_ios.go | 113 +++++++++++++----------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/internal/uidriver/mobile/vibrate_ios.go b/internal/uidriver/mobile/vibrate_ios.go index 2e7eff3b5..01db64cac 100644 --- a/internal/uidriver/mobile/vibrate_ios.go +++ b/internal/uidriver/mobile/vibrate_ios.go @@ -21,66 +21,75 @@ package mobile // // #import // -// static CHHapticEngine* engine; +// static id initializeHapticEngine(void) { +// if (@available(iOS 13.0, *)) { +// if (!CHHapticEngine.capabilitiesForHardware.supportsHaptics) { +// return nil; +// } // -// static void initializeVibrate(void) { -// if (!CHHapticEngine.capabilitiesForHardware.supportsHaptics) { -// return; -// } +// NSError* error = nil; +// CHHapticEngine* engine = [[CHHapticEngine alloc] initAndReturnError:&error]; +// if (error) { +// return nil; +// } // -// NSError* error = nil; -// engine = [[CHHapticEngine alloc] initAndReturnError:&error]; -// if (error) { -// return; -// } -// -// [engine startAndReturnError:&error]; -// if (error) { -// return; +// [engine startAndReturnError:&error]; +// if (error) { +// return nil; +// } +// return engine; // } +// return nil; // } // // static void vibrate(double duration) { -// if (!engine) { -// return; -// } -// -// @autoreleasepool { -// NSDictionary* hapticDict = @{ -// CHHapticPatternKeyPattern: @[ -// @{ -// CHHapticPatternKeyEvent: @{ -// CHHapticPatternKeyEventType:CHHapticEventTypeHapticContinuous, -// CHHapticPatternKeyTime:@0.0, -// CHHapticPatternKeyEventDuration:[NSNumber numberWithDouble:duration], -// CHHapticPatternKeyEventParameters:@[ -// @{ -// CHHapticPatternKeyParameterID: CHHapticEventParameterIDHapticIntensity, -// CHHapticPatternKeyParameterValue: @1.0, -// }, -// ], +// if (@available(iOS 13.0, *)) { +// static BOOL initializeHapticEngineCalled = NO; +// static CHHapticEngine* engine = nil; +// if (!initializeHapticEngineCalled) { +// engine = (CHHapticEngine*)initializeHapticEngine(); +// initializeHapticEngineCalled = YES; +// } +// if (!engine) { +// return; +// } +// @autoreleasepool { +// NSDictionary* hapticDict = @{ +// (id)(CHHapticPatternKeyPattern): @[ +// @{ +// (id)(CHHapticPatternKeyEvent): @{ +// (id)(CHHapticPatternKeyEventType):CHHapticEventTypeHapticContinuous, +// (id)(CHHapticPatternKeyTime):@0.0, +// (id)(CHHapticPatternKeyEventDuration):[NSNumber numberWithDouble:duration], +// (id)(CHHapticPatternKeyEventParameters):@[ +// @{ +// (id)(CHHapticPatternKeyParameterID): CHHapticEventParameterIDHapticIntensity, +// (id)(CHHapticPatternKeyParameterValue): @1.0, +// }, +// ], +// }, // }, -// }, -// ], -// }; +// ], +// }; // -// NSError* error = nil; -// CHHapticPattern* pattern = [[CHHapticPattern alloc] initWithDictionary:hapticDict -// error:&error]; -// if (error) { -// return; -// } +// NSError* error = nil; +// CHHapticPattern* pattern = [[CHHapticPattern alloc] initWithDictionary:hapticDict +// error:&error]; +// if (error) { +// return; +// } // -// id player = [engine createPlayerWithPattern:pattern -// error:&error]; -// if (error) { -// return; -// } +// id player = [engine createPlayerWithPattern:pattern +// error:&error]; +// if (error) { +// return; +// } // -// [player startAtTime:0 error:&error]; -// if (error) { -// NSLog(@"3, %@", [error localizedDescription]); -// return; +// [player startAtTime:0 error:&error]; +// if (error) { +// NSLog(@"3, %@", [error localizedDescription]); +// return; +// } // } // } // } @@ -92,10 +101,6 @@ import ( "time" ) -func init() { - C.initializeVibrate() -} - var vibrationM sync.Mutex func (u *UserInterface) Vibrate(duration time.Duration) {