跳到主要内容
版本:4.0.0

🪝 弹窗自动化模块

弹窗自动化模块 - alert

此模块辅助脚本处理 UIKit 系统内建弹窗控制器 UIAlertController (下称 “标准弹窗”)以及 Safari 网页弹窗。

限制
  • 受限于你所在地区的法律法规,你可能无法取得、使用此模块。
  • 无法在受到著作权保护的 App 中调用(你只能在自己开发的 App 中调用它们)。
提示
  • 此模块支持以 OpenAPI 方式独立调用。

打开、关闭弹窗日志 (alert.enable_logging/alert.disable_logging)

声明

alert.enable_logging()   -- 打开弹窗日志
alert.disable_logging() -- 关闭弹窗日志

说明

打开或关闭弹窗日志,弹窗日志默认关闭。打开弹窗日志后:

  • App 运行时的 标准弹窗 和 Safari 网页弹窗会在控制台输出弹窗日志,并转储到 <应用数据容器路径>/Library/Caches/ch.xxtou.AlertHelper/<应用标识符>.log
  • 春板 com.apple.springboard 及系统内建 App 运行时的 标准弹窗 会在控制台输出弹窗日志,并转储到 /var/mobile/Library/Caches/ch.xxtou.AlertHelper/<应用标识符>.log
  • 应用数据容器路径 可通过 app.data_path 函数获取。

示例输出

com.saurik.cydia
-- 带输入框的弹窗
{
style = "alert", -- 弹窗类型,alert 表示普通弹窗,action-sheet 表示动作菜单
class = "UIAlertController", -- 弹窗的 Objective-C 类名
title = "Enter Cydia/APT URL", -- 弹窗标题内容
message = "", -- 弹窗消息内容
actions = { -- 弹窗按钮列表
{
enabled = true, -- 按钮是否可用
style = "cancel", -- 按钮类型,cancel 表示取消按钮,default 表示默认按钮
title = "Cancel", -- 按钮标题内容
},
{
enabled = true,
style = "default",
title = "Add Source",
},
},
textfields = { -- 弹窗输入框列表
{
placeholder = "", -- 输入框占位符
text = "https://", -- 输入框内容
},
},
}
com.apple.Preferences
--
-- 多按钮的弹窗
{
style = "alert",
class = "UIAlertController",
title = "Apple ID",
message = "i.82@me.com",
actions = {
{
enabled = true,
style = "default",
title = "View Apple ID",
},
{
enabled = true,
style = "default",
title = "Sign Out",
},
{
enabled = true,
style = "default",
title = "iForgot",
},
{
enabled = true,
style = "default",
title = "Cancel",
},
},
textfields = {},
}
--
-- 动作菜单
{
style = "action-sheet",
class = "UIAlertController",
title = "This will reset your location and privacy settings to factory defaults.",
message = "",
actions = {
{
enabled = true,
style = "destructive",
title = "Reset Settings",
},
{
enabled = true,
style = "cancel",
title = "Cancel",
},
},
textfields = {},
}
com.apple.mobilesafari
-- Safari 网页弹窗 window.prompt
{
style = "alert",
class = "_SFDialogController",
title = "",
message = "Please enter your name",
actions = {
{
enabled = true,
style = "default",
title = "OK",
},
{
enabled = true,
style = "cancel",
title = "Cancel",
},
},
textfields = {
{
placeholder = "",
text = "Harry Potter",
},
{
placeholder = "",
text = "",
},
},
}

打开、关闭弹窗自动绕过 (alert.enable_autopass/alert.disable_autopass)

声明

alert.enable_autopass()   -- 打开弹窗自动绕过
alert.disable_autopass() -- 关闭弹窗自动绕过

说明

打开或关闭弹窗自动绕过,弹窗自动绕过默认关闭。打开弹窗自动绕过后:

  • App 运行时的 标准弹窗 和 Safari 网页弹窗会自动以点击 “取消” 的方式绕过,不会停留在屏幕上。
  • 春板 com.apple.springboard 及系统内建 App 运行时的 标准弹窗 会自动以点击 “取消” 的方式绕过,不会停留在屏幕上。
  • 弹窗自动绕过不会影响弹窗日志的输出。

设置弹窗自动绕过延迟 (alert.set_autopass_delay)

声明

alert.set_autopass_delay(延迟毫秒)

参数及返回值

  • 延迟毫秒
    • 整数型,弹窗自动绕过延迟的毫秒数,取值范围为 100.0 ~ 10000.0,默认为 1000.0,即 1 秒

示例

alert.set_autopass_delay
alert.enable_autopass()
alert.set_autopass_delay(200) -- 设置弹窗自动绕过延迟为 0.2 秒

获取最前方的弹窗 (alert.get_topmost)

声明

弹窗信息表 = alert.get_topmost()

参数及返回值

  • 弹窗信息表
    • 关联表,其结构参见 示例输出,如果没有弹窗则返回 nil

消除最前方的弹窗 (alert.dismiss_topmost)

声明 1

操作成败, 失败原因 = alert.dismiss_topmost([ 按钮名称 或 按钮索引 ])

声明 2

操作成败, 失败原因 = alert.dismiss_topmost {
action = 按钮名称 或 按钮索引,
textfields = {
[文本框索引] = 文本框内容,
...
},
}

参数及返回值

  • 按钮名称
    • 文本型可选,弹窗上的按钮名称,如 “OK”、“Cancel”、“Reset Settings” 等
  • 按钮索引
    • 整数型可选,弹窗上的按钮索引,从 1 开始
  • 文本框索引
    • 整数型可选,弹窗上的文本框索引,从 1 开始
  • 文本框内容
    • 文本型可选,填入弹窗上对应 文本框索引 的文本框内容
  • 失败原因 文本型
  • 操作成败 布尔型

说明

如果不填写任何参数,则默认点击最前方弹窗上的 第一个按钮
如果弹窗上有文本框,则默认不填写文本框内容。

示例

alert.dismiss_topmost
alert.dismiss_topmost()          -- 点击最前方弹窗上的第一个按钮
--
alert.dismiss_topmost("Cancel") -- 点击最前方弹窗上的 “Cancel” 按钮
--
alert.dismiss_topmost(2) -- 点击最前方弹窗上的第二个按钮
--
alert.dismiss_topmost {
action = "OK",
textfields = {
[1] = "Harry Potter",
[2] = "Hogwarts",
},
} -- 点击最前方弹窗上的 “OK” 按钮,并填写文本框内容

获取、设置 App 弹窗规则 (alert.get_local_rules/alert.set_local_rules)

声明

弹窗规则表 = alert.get_local_rules(标识符)  -- 获取 App 弹窗规则
alert.set_local_rules(标识符, 弹窗规则表) -- 设置 App 弹窗规则

参数及返回值

  • 标识符
  • 弹窗规则表
    • 顺序表,结构如下。其中每一条弹窗规则为一个 关联表

弹窗规则表

alert.set_local_rules
alert.set_local_rules("com.saurik.Cydia", {
{
title = "^About Cydia Installer$", -- 通过标题过滤弹框(正则表达式)
action = { title = "Close" }, -- 通过标题指定动作(正则表达式)
action = 1, -- 通过索引指定动作(以 1 为起始)
},
{
title = "^Verification Error$",
action = { title = "OK" },
action = "OK", -- 通过标题指定动作(简写)
},
{
title = "^Enter Cydia\\/APT URL$",
textfields = {
{ text = "https://build.frida.re" }, -- 指定文本框内容
},
textfields = { "https://" }, -- 指定文本框内容(简写)
action = {
title = "Add Source",
delay = 500.0, -- 设置动作延迟(毫秒)
},
},
{
style = "alert", -- 通过样式过滤弹框
message = "^Please enter your name", -- 通过消息过滤弹框(正则表达式)
textfields = { "Harry Potter" },
action = "OK",
},
...
})
--
alert.get_local_rules("com.saurik.Cydia")

说明

不会校验 标识符弹窗规则表 的合法性,如果传入的参数不合法,可能会导致弹窗规则不生效或 App 闪退。

清除 App 弹窗规则 (alert.clear_local_rules)

声明

alert.clear_local_rules(标识符)

参数及返回值

示例

alert.clear_local_rules
alert.clear_local_rules("com.saurik.Cydia")

获取、设置全局弹窗规则 (alert.get_global_rules/alert.set_global_rules)

声明

弹窗规则表 = alert.get_global_rules()  -- 获取全局弹窗规则
alert.set_global_rules(弹窗规则表) -- 设置全局弹窗规则

参数及返回值

说明

全局弹窗规则会作用于所有 App。
不会校验 弹窗规则表 的合法性,如果传入的参数不合法,可能会导致弹窗规则不生效或 App 闪退。

清除全局弹窗规则 (alert.clear_global_rules)

声明

alert.clear_global_rules()

说明

清除全局弹窗规则,不会影响 App 弹窗规则。