CheatCodes 是一个可以用于在模拟器中启用调试功能并使用 UIKeyCommand
的即插式工具。它还提供了构建自己的自定义命令的工具,并提供格式化的输出。
以下命令为默认可用:
Available Cheat Codes:
======================
⌘ + ⇧ + ^ + ↓: Trigger restorable state preservation
⇧ + ^ + d: Print documents directory path
⇧ + ^ + e: Re-enable user interaction
⌘ + ⌥ + f: Reset all first run screens
⇧ + ^ + g: Log in a default user account
⇧ + ^ + h: Print the list of available commands
⇧ + ^ + i: Print general device info
⇧ + ^ + l: Print autolayout backtrace
⇧ + ^ + o: Print the current trait collection (for the main window)
⇧ + ^ + t: Cycle tintAdjustmentMode
⇧ + ^ + u: Print user defaults
虽然此库配置为在“发布”构建中将本身完全留空,但您的项目可能使用不同的构建配置名称为应用商店发布。您应确保此库不在任何公开可用的构建中可用。
在 Xcode 8 中,将以下内容添加到项目的 Active Compilation Conditions
(SWIFT_ACTIVE_COMPILATION_CONDITIONS)下
Active Compilation Conditions > Debug > CHEATS_ENABLED
class AppDelegate {
#if CHEATS_ENABLED
override var keyCommands: [UIKeyCommand]? {
return UIKeyCommand.cheatCodes
}
#endif
}
#if CHEATS_ENABLED
extension AppDelegate {
func configureCustomCheats() {
[
CheatCodeCommand(input: "g", action: #selector(logInUser), discoverabilityTitle: "Log in a default user account"),
CheatCodeCommand(input: "f", modifierFlags: [.command, .alternate], action: #selector(resetFirstRunScreens), discoverabilityTitle: "Reset all first run screens"),
].forEach { UIKeyCommand.addCheatCode($0) }
}
func logInUser() {
print("Log in a user")
}
func resetFirstRunScreens() {
print("First run screens reset!")
}
}
#endif
虽然您将看不到重叠提示,表示可以使用的项目,但这些实际上在 iPhone 模拟器上确实有效(请确保已启用 Hardware > Keyboard > Connect Hardware Keyboard
)
要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install
CheatCodes 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod "CheatCodes"
Dave Lyon,[email protected]
CheatCodes 在 MIT 许可协议下提供。有关更多信息,请参阅 LICENSE 文件。