【问题标题】:How can I get UIButton to call target class and hook this method? (using theos to compile jailbreak tweak)如何让 UIButton 调用目标类并挂钩此方法? (使用theos编译越狱调整)
【发布时间】:2014-09-10 07:01:04
【问题描述】:

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

【问题讨论】:

    标签: ios objective-c iphone jailbreak theos


    【解决方案1】:

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

    -(void)buttonPressed:(id)sender 
    

    或将目标更改为:

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

    【讨论】:

    • 按下按钮时如何让它调用 forceMMS?
    • 我不知道chatkit,它只是正确挂钩方法的方法
    【解决方案2】:

    带有徽标的 Opsss 来定义你必须编写的新动作/方法

    %new 在这个动作或方法之前

    我建议你创建一个私有类来使用这样的操作

    [self buttonPressed];
    

    私有类应该看起来像

    @interface CKTranscriptCollectionViewController (TWEAKNAME)
    -(void)buttonPressed;
    @end
    

    所以你的代码应该看起来像

    #import <UIKit/UIKit.h>
    #import <ChatKit/ChatKit.h>
    
    @interface CKTranscriptCollectionViewController : UIViewController
    @end
    
    @interface CKTranscriptCollectionViewController (TWEAKNAME)
    -(void)buttonPressed;
    @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]; 
    }
    
    %new
    -(void)buttonPressed {
        NSLog(@"Button Pressed!");
    }
    
    %end
    

    祝你好运

    【讨论】:

    • 它可以工作,但现在我如何让它在点击时调用它:%hook CKConversation -(BOOL)forceMMS { return TRUE; } %结束
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多