0

我想为挂钩 uitextfield 或 uitextview 开发简单的调整。我的代码如下

%hook UITextView

-(id)initWithFrame:(CGRect)frame webView:(id)view
{
    UIAlertView *keyAlert = [[UIAlertView alloc] initWithTitle:@"testApp" message:@"Test" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [keyAlert show];
    [keyAlert release];

    return %orig;
}
%end

它执行成功,但我无法获得任何输出。请检查此调整并帮助我,如果我走错了方向,请建议我。

谢谢。

4

1 回答 1

2

您可能在这里做错了两件事:

1) UITextView 不一定在初始化时调用该方法;它可能正在调用 -initWithFrame: 、 -initWithFrame:font: 或 -initWithFrame:webView: (或者甚至只是 -init,稍后会设置框架)。您应该挂钩所有案例,看看您是否得到任何结果以及其中一个结果。

%hook UITextView
-(id)initWithFrame:(CGRect)frame
{
    %log; // conveniently NSLogs self,selector,arguments
    return %orig;
}
-(id)initWithFrame:(CGRect)frame font:(UIFont *)font
{
    %log; 
    return %orig;
}
-(id)initWithFrame:(CGRect)frame webView:(UIWebView *)webView
{
    %log; 
    return %orig;
}
%end

2) Make sure the process you're hooking onto is the one calling the method. If your project's plist filters "com.apple.springboard" and you're testing this into another app, e.g. "com.apple.mobilesafari", it won't work.

于 2012-10-16T19:02:58.893 回答