Phase 1.15:VibratorHandler 单次振动 handler
新增 ylgamehall/Source/Bridge/Handlers/VibratorHandler.swift:
- 无状态 public enum VibratorHandler,static func register(on:)
- 入参忽略(参考原 msext RootVC.m:1816-1818:time 参数实际不读取)
- 副作用:AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
- responseCallback:.string("vibrator"),与契约 §3.1 [10]一致
- 模拟器无振动硬件、调用静默忽略;真机才能感知
WebContainerViewController.viewDidLoad 新增 registerBridgeHandlers()
单一聚合点,Phase 2+ 在此追加更多 handler,便于发现 / 调试。
repeatvibrator / canclevibrator 严格守住 Plan §5 Phase 2.2 范围,不
提前实现。
BuildProject 通过
Plan 进度已勾选(§5 Phase 1.15 + §8)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
a20498f898
commit
6c943e2924
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// VibratorHandler.swift
|
||||
// ylgamehall
|
||||
//
|
||||
// H5 → Native handler「vibrator」(契约 §3.1 [10]:单次振动)。
|
||||
// Phase 1.15 仅实现这一项作为最小垂直闭环验证标的;
|
||||
// `repeatvibrator` / `canclevibrator` 放到 Phase 2.2 一并补齐。
|
||||
//
|
||||
|
||||
import AudioToolbox
|
||||
|
||||
/// 单次振动 handler 注册器。
|
||||
///
|
||||
/// 设计为无状态 enum:震动调用是无状态的 C API,不需要持有任何资源;
|
||||
/// 同时避免误把 handler 注册器实例化保留,造成"注册多份"。
|
||||
public enum VibratorHandler {
|
||||
|
||||
/// 在 `bridge` 上注册 `vibrator` handler。
|
||||
///
|
||||
/// 契约(`docs/H5-Native-Contract.md` §3.1 [10]):
|
||||
/// - 入参:被忽略(参考原 msext `RootVC.m:1816-1818` 入参 `time` 实际不读取)
|
||||
/// - 副作用:`AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)`
|
||||
/// - responseCallback:字符串 `"vibrator"`
|
||||
///
|
||||
/// 模拟器无振动硬件,调用会被静默忽略(不抛异常),真机才能感知。
|
||||
public static func register(on bridge: any BridgeProtocol) {
|
||||
bridge.register("vibrator") { _, callback in
|
||||
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
|
||||
callback?(.string("vibrator"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,12 +40,19 @@ public final class WebContainerViewController: UIViewController {
|
||||
setupSplash()
|
||||
|
||||
bridgedWebView.webView.navigationDelegate = self
|
||||
registerBridgeHandlers()
|
||||
|
||||
Task { @MainActor in
|
||||
await runBootPipeline()
|
||||
}
|
||||
}
|
||||
|
||||
/// 注册所有 H5 → Native handler。Phase 1.15 仅 `vibrator`;
|
||||
/// 后续 Phase 2+ 在此追加更多 handler(保持单一聚合点便于发现 / 调试)。
|
||||
private func registerBridgeHandlers() {
|
||||
VibratorHandler.register(on: bridgedWebView.bridge)
|
||||
}
|
||||
|
||||
public override var supportedInterfaceOrientations: UIInterfaceOrientationMask { .landscape }
|
||||
public override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { .landscapeRight }
|
||||
public override var prefersStatusBarHidden: Bool { false }
|
||||
|
||||
Reference in New Issue
Block a user