ios - 如何让 UIButton 调用目标类并 Hook 此方法? (使用theos编译越狱tweak)

标签 ios objective-c iphone jailbreak theos

我正在尝试将 UIButton 放入 iPhone 的 MobileSMS.app(消息应用程序)中。它成功地出现在 View 中,但是当您按下它时,它当然会崩溃,因为它没有调用任何目标类并 Hook 方法。我想要 Hook 的目标类和方法在下面的第二个代码中,如何实现按下按钮时调用它? (我的主要目标是在对话 View 中放置一个按钮,当点击它时,它将强制发送短信,而不是自动使用 iMessage。)

#import <UIKit/UIKit.h>
#import <ChatKit/ChatKit.h>

@interface CKTranscriptCollectionViewController : UIViewController
@end

%hook CKTranscriptCollectionViewController
-(void)loadView {
   %orig;
   UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
   [button setTitle:@"SMS" forState:UIControlStateNormal]; 
   button.frame = CGRectMake(0, 0, 50, 100);
   [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
   [self.view addSubview:button]; 
}

-(void)buttonPressed {
    NSLog(@"Button Pressed!");
}

%end

我想在点击按钮时调用的类和方法(属于标题“ChatKit/CKConversation.h”):

%hook CKConversation
-(BOOL)forceMMS {

    return TRUE;

}
%end

最佳答案

它崩溃是因为它检查了一个参数。尝试将方法定义更改为:

-(void)buttonPressed:(id)sender 

或将目标更改为:

[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

关于ios - 如何让 UIButton 调用目标类并 Hook 此方法? (使用theos编译越狱tweak),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25759174/

相关文章:

ios - 核心数据迁移示例

javascript - 在 iOS 移动版 Safari 13(iPhone X 和 11)中隐藏全屏网络应用程序的状态/位置栏

iphone - ARC 释放子类 NSObject,但不释放自定义 NSObject

iOS - 防止重复将事件添加到日历

ios - 如何设置 UIScrollview 和动画的优先级

ios - SwiftUI - 所有可见的 3 列/侧边栏布局?

ios - iPhone : Capture iOS Camera with Overlay View

ios - 生成唯一的 uibutton 标签

objective-c - 阻止第三方 iOS 框架的网络访问

objective-c - 隐藏 UISearchBar 取消按钮