ClamshellKit 面向 macOS 平台,以 Swift SDK 形式读取 Mac 笔记本的屏幕开合角度,并通过 Swift Concurrency 获取角速度、角加速度和实时变化
Important
屏幕开合角度不是公开、稳定的系统能力,兼容性可能因机型、系统版本和运行环境而异。
角速度和角加速度为连续角度样本的估算值。请在实际设备上检查 status 并处理读取错误
-
选择 File > Add Package Dependencies…
-
输入地址
https://github.com/bob-zebedy/ClamshellKit.git -
将
Dependency Rule设置为 Exact Version 填写对应的 Tag 版本 -
将
ClamshellKit添加到 macOS App 的target
将 ClamshellKit 添加到包的依赖中
dependencies: [
.package(
url: "https://github.com/bob-zebedy/ClamshellKit.git",
exact: "x.x.x"
)
]然后在对应的 target 中引用
dependencies: [
.product(name: "ClamshellKit", package: "ClamshellKit")
]在支持 async throws 的上下文中读取当前角度
import ClamshellKit
let monitor = ClamshellMonitor()
let angle = try await monitor.angle()
print("角度: \(angle.degrees)°")使用、兼容性、完整读数、持续观察及错误处理请参阅 使用指南