我正在尝试将 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/