You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用theos hook SBStatusBarManager实现点击状态栏弹窗的编译错误求助

报错原因及修复方案

错误1:UIAlertController方法调用错误

alertControllerWithTitle:message:preferredStyle: 是UIAlertController的类方法,不需要先通过alloc创建实例再调用,直接用类对象调用即可,你之前的写法将类方法当做实例方法调用,所以找不到对应选择器。

错误2:present方法调用对象错误

SBStatusBarManager 是状态栏管理类,并非UIViewController子类,本身不具备presentViewController:animated:completion:方法,需要获取当前系统的顶层视图控制器来执行弹窗操作。

修复后的完整代码

#include <UIKit/UIKit.h>

%hook SBStatusBarManager

-(void)handleStatusBarTapWithEvent:(id)arg1{
    // 正确调用类方法创建UIAlertController
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"I hope this works!" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
    [alert addAction:defaultAction];
    
    // 获取顶层视图控制器弹出提示框
    UIViewController *topVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    [topVC presentViewController:alert animated:YES completion:nil];

    %orig;
}

%end

补充说明

如果部分系统版本下keyWindow获取异常,可以替换为遍历[UIApplication sharedApplication].windows数组获取当前激活的窗口再取rootViewController即可。

内容的提问来源于stack exchange,提问作者wretchedbeaches

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 04:48:01