Files
youle_app_ios_v2/ylgamehall/Source/Bridge/Handlers/VibratorHandler.swift
T
joywayerandClaude Opus 4.7 d38ff0f8c4 Phase 2.A:大厅 8 个简单 handler 落地 + BridgeData 加 nonisolated
闭合 Phase 1.17 联调最后一公里(解决 Xcode 日志 4 个 "no handler registered"
+ 提前落地 4 个无外部依赖的简单 handler)。

新增 7 个 handler 模块(Source/Bridge/Handlers/):
  - ClipboardHandler.swift           §3.1 [13][14]剪贴板 UIPasteboard.general
  - ShakeHandler.swift               §3.1 [7][8][9]摇一摇 + §3.2 [5]shakeEnd 反向
                                       canShake / canVoice 状态 + motionEnded 转发钩子
  - VoicePlayingHandler.swift        §3.1 [6]actor VoiceCenter.shared 开关位
  - DeviceInfoHandler.swift          §3.1 [21]+ §3.2 [1]getphoneInfo 大写 I 入、
                                       getphoneinfo 小写 i 出反向 callback
                                       DeviceInfoSnapshot 6 字段(IDFA 用 idfv 兜底,
                                       CLAUDE.md 不接 ATT/IDFA)
  - BrowserHandler.swift             §3.1 [16]UIApplication.open async(Task @MainActor
                                       异步打开,闭包先 cb 不等 open 完成)
  - OpenSaomaHandler.swift           §3.1 [22]空 stub(契约要求注册)
  - StartLocationHandler.swift       §3.1 [20]Phase 5 完整实现,Phase 2 stub

扩展 VibratorHandler.swift:
  - §3.1 [10]vibrator(原有)+ [11]repeatvibrator(msext RootVC.m:1820 沿用:
    实际单次 vibrate 不真循环)+ [12]canclevibrator

BridgeProtocol.swift BridgeData 加 nonisolated:
  - 项目默认 SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor 让 BridgeData 跨 actor
    访问被拦;asString / asDouble / asInt / asBool / asArray / asObject /
    subscript 全部标 nonisolated(纯值类型本就该是 isolation-free)
  - 影响所有 @Sendable async handler 闭包内的 data?.asXxx 访问

WebContainerViewController 接入:
  - 加 private let shakeHandler = ShakeHandler() 持有
  - registerBridgeHandlers() 注册 8 个 handler 模块
  - 加 canBecomeFirstResponder = true + viewDidAppear becomeFirstResponder
  - 加 motionEnded(_:with:) 转发到 shakeHandler.handleMotionEnded
    (motion 检测必需 first responder,否则不触发)

BuildProject 通过。重装 app 后 H5 启动应不再报 "no handler registered" 错误。

Plan §5 Phase 2.A 全部勾选(含 startlocation bonus stub + BridgeData
nonisolated 重构)。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-22 18:38:00 +08:00

40 lines
1.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// VibratorHandler.swift
// ylgamehall
//
// H5 → Native handler 三件套:vibrator / repeatvibrator / canclevibrator
// 契约:docs/H5-Native-Contract.md §3.1 10][11][12
// 原项目:daoqi/msext RootVC.m:1816-1834
//
import AudioToolbox
/// 振动 handler 注册器(无状态 enum)。
public enum VibratorHandler {
/// 注册三个振动 handler。
public static func register(on bridge: any BridgeProtocol) {
// 【10】vibrator — 单次振动
// 入参忽略;副作用:AudioServicesPlaySystemSoundcb "vibrator"
bridge.register("vibrator") { _, callback in
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
callback?(.string("vibrator"))
}
// 【11】repeatvibrator — 重复振动(msext RootVC.m:1820 实际就是单次 vibrate
// 不真的循环,沿用历史)
bridge.register("repeatvibrator") { _, callback in
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
callback?(.string("repeatvibrator"))
}
// 【12】canclevibrator — 释放系统振动音
// AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate) 对系统常量
// 意义有限,但 H5 仍会调,必须 noop + cb 维持契约
bridge.register("canclevibrator") { _, callback in
AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate)
callback?(.string("canclevibrator"))
}
}
}