您是否曾经想知道您的应用程序用户实际启用了哪些无障碍功能? 您是否希望能够根据来自用户群的真实数据,轻松确定应该对您的应用程序进行的无障碍改进的优先级?
A11yoopMonitor
允许您跟踪用户在使用您的应用程序时,在其 iOS 设备上启用了哪些无障碍功能。 它可以轻松集成到现有应用程序中,并提供了一种简单的方法来跟踪用户在其设备上启用/禁用功能的状态变化。 它也具有高度的可扩展性,提供了一个简单的 API,允许您对接收到的数据进行任何您想做的处理。
值得一提的是,A11yoopMonitor
跟踪的任何数据都是完全匿名的,并且无法识别任何用户。 它仅提供一个统一的 API,用于确定无障碍功能状态的变化。
当您实例化 A11yoopMonitor
时,您可以选择指定要监控的无障碍功能。 这些可以由您选择,也可以省略,默认情况下将监控所有可观察的无障碍功能。
import A11yoopMonitor
final class MyClass {
// In order to only monitor specific accessibility features (eg. voice over and larger text):
let specificMonitor = A11yoopMonitor(featureTypes: [.voiceOver, .largerText])
// In order to monitor all observable accessibility features:
let defaultMonitor = A11yoopMonitor()
}
一旦您实例化了 A11yoopMonitor
,就可以随时查询观察到的无障碍功能的当前状态。 这可以通过以下方式完成
let monitor = A11yoopMonitor(featureTypes: [.voiceOver, ...])
// In order to query current status of voice over accessibility feature
let status = monitor.isFeatureEnabled(.voiceOver)
当查询当前未被监控的无障碍功能的状态时,结果状态将为 .notMonitored
。
let monitor = A11yoopMonitor(featureTypes: [.voiceOver]) // Only monitors voice over
let status = monitor.isFeatureEnabled(.boldText) // Query an accessibility feature that isn't monitored
/// - .notMonitored
最后,如果您监控的无障碍功能在用户的设备上当前不受支持,则状态将返回为 .notSupported
。
为了便于与第三方分析 SDK APIs 集成,A11yoopMonitor
提供了一种将所有当前监控的无障碍功能转换为参数字典(类型为 [String: Any]
)的方法,该字典与大多数分析 SDK APIs 兼容。 此字典将包含键值对,将功能类型描述映射到当前功能状态描述(例如,["Bold Text": "Disabled"
])。
可以使用 asAnalyticsParams(prefixedBy:)
适配器进行此转换,该适配器将 A11yFeature
序列转换为 [String: Any]
表示形式。
一个示例用例是将无障碍功能状态包含在跟踪事件中
func sendEvent() {
let params = self.monitor.allFeatures.asAnalyticsParams()
let eventName = "A11yoop features"
// Firebase
Analytics.logEvent(eventName, parameters: params)
}
为了防止冲突,还可以传递一个前缀,该前缀将应用于所有参数键(例如,应用前缀后产生 "A11yoop Bold Text",而不是没有前缀的 "Bold Text")。
或者,如果您想以完全不同的方式表示受监控的无障碍功能,则可以使用许多计算属性来方便使用。 这些如下
// `.enabledFeatures` provides only the monitored accessibility features that are currently enabled.
let formattedEnabledFeatures = self.monitor.enabledFeatures.map(\.type.description).joined(separator: ",")
// `.disabledFeatures` provides only the monitored accessibility features that are currently disabled.
let formattedDisabledFeatures = self.monitor.disabledFeatures.map(\.type.description).joined(separator: ",")
// `.unsupportedFeatures` provides only the monitored accessibility features that are unsupported.
let formattedUnsupportedFeatures = self.monitor.unsupportedFeatures.map(\.type.description).joined(separator: ",")
这允许您以您想要的任何方式格式化它们(例如,作为逗号分隔的字符串)。
可以编写自定义发射器,以便以您想要的任何方式对无障碍功能状态更改做出反应。 例如,如果您想发送特定于每个无障碍功能的单独分析事件(而不是使用 asAnalyticsParams(prefixedBy:)
),那么实现此目的的最佳方法是编写您自己的自定义发射器。
这可以通过扩展 A11yStatusEmitter
并创建您自己的静态配置来完成,然后将其包含在您的 A11yoopMonitor(featureTypes:emitters:)
初始化中
extension A11yStatusEmitter {
static var analyticsEventEmitter: Self {
Self { feature in
// The feature argument is the updated feature. Do with it whatever you want...
Analytics.logEvent(
"A11yoop Feature Updated",
parameters: [feature.type.description: feature.status.description])
}
}
}
final class MyClass {
// Include the custom emitter in your `A11yoopMonitor` initialisation
let monitor = A11yoopMonitor(emitters: [.analyticsEventEmitter, .log())
}
目前可以使用 Swift Package Manager 安装此库。 为此,请使用 Xcode 将当前存储库添加为包依赖项,或在您的 Package.swift
文件中包含以下内容
import PackageDescription
let package = Package(
...
dependencies: [
.package(url: "https://github.com/Jackstone92/A11yoop", .upToNextMajor(from: "3.1.0")),
],
...
targets: [
.target(name: "MyTarget", dependencies: ["A11yoop"]),
]
)
有关 A11yoopMonitor
如何在您的应用程序中使用的更多信息,请查看预览应用程序。 这提供了一个playground环境,您可以在其中切换无障碍功能并跟踪应用程序中的更改。 所有更改都使用 A11yoopMonitor
进行监控。
欢迎对 A11yoop 进行任何贡献,无论是功能请求、错误报告还是任何一般性问题和反馈! 如果您想贡献,请快速浏览一下贡献指南。
版权所有 2021 © Jack Stone
A11yoop 在 MIT 许可证 下提供。