%hook FirstClass
[self method2];
%orig
%end
但是method2
只能在不同的类中使用
在这种情况下我该如何调用它?
目前我所知道的:
- 使用NotificationCenter通知二类加载
method2
- 与使用
%c
有一些关系,但不熟悉完整的解释
但是这太复杂了,有没有其他方法可以做到这一点
-- 更新
我尝试了 %c 但我得到了这个错误
Tweak.xm:86:48: error: class method '+class' not found (return type
defaults to 'id') [-Werror,-Wobjc-method-access]
^~~~~~~~~~~~~~~~~~
此处应用的解决方案> THEOS: compiling error when calling method in other class (logos)
但是好像不行
最佳答案
要调用另一个类的方法,它必须是类方法(加号)。然后您可以执行 [%c(ClassName) method:];
如果它不是类方法(减号),那么您将必须拥有该类的实例。有时您可以找到一个类的共享实例,然后对其使用方法。 [[%c(ClassName) sharedInstance].propertyWhichIsOfAClassYouActuallyWant 方法:]
关于ios - 从我在 theos 中的钩子(Hook)类调用不同的类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28101534/