简体   繁体   English

Theos实例方法调用

[英]Theos instance method calling

I have searched for an answer to this and cannot find one. 我已经找到了答案,找不到答案。

How would I call an instance method in the same class I am hooking in my Theos tweak? 我如何调用我在Theos调整中挂钩的同一个类中的实例方法? If I was using standard Xcode i would use the self method ie- 如果我使用标准Xcode,我会使用自我方法,即 -

[self method:arg];

But in a theos tweak this says cannot find the method, even if i hook that method. 但是在一个theos调整中,这说法找不到方法,即使我挂钩那个方法。

Example: 例:

%hook classimhooking

-(void)methodimhooking
{
    [classimhooking methodiwanttocall];
    [self methodiwanttocall];
    %orig;
}

-(void)methodiwanttocall
{
    %orig;
}

%end

The methodiwanttocall is there and i can hook to it, just not call it. methodiwanttocall在那里,我可以挂钩,只是没有打电话给它。 I have tried adding a new method with %new and calling that but it is not found, i have tried the same with a delay, but it is not found. 我已经尝试使用%new添加一个新方法并调用它但是找不到,我尝试了同样的延迟,但是找不到它。 I have tried defining a variable of my class and calling that but it doesn't work. 我已经尝试定义我的类的变量并调用它但它不起作用。

I can also see that you can grab iVars directly, but this doesn't work with methods. 我还可以看到你可以直接获取iVars,但这不适用于方法。

Any ideas would be appreciated. 任何想法,将不胜感激。

如果要在刚挂接的对象上调用方法,可以使用performSelector (或performSelector:withObject:如果它有参数),这应该是这样的:

[self performSelector:@selector(methodiwanttocall)];

Sorry to dig an old thread. 抱歉挖掘旧线程。 I may have an idea about the issue here. 我可能对这个问题有所了解。 In case anyone with the same issue comes across this. 万一有相同问题的人遇到这个问题。

The problem is that the compiler does not know there is such a method, even there is. 问题是编译器不知道有这样的方法,即使有。 The way to deal with it is to import the header at the top of the code. 处理它的方法是导入代码顶部的标题。

#import <classimhooking>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM