【问题标题】:Call different class method from my hooked class in theos从我在theos中的钩子类中调用不同的类方法
【发布时间】:2015-01-23 01:13:57
【问题描述】:
%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)

但似乎不起作用

【问题讨论】:

  • 嗨。你能再解释一下吗?您将使用哪些类?请在更新中写下您正在谈论的代码。

标签: ios objective-c jailbreak theos


【解决方案1】:

要调用另一个类的方法,它必须是类方法(加号)。然后您可以执行[%c(ClassName) method:]; 如果它不是类方法(减号),那么您将必须拥有该类的实例。有时您可以找到一个类的共享实例,然后在其上使用方法。 [[%c(ClassName) sharedInstance].propertyWhichIsOfAClassYouActuallyWant method:]

【讨论】:

  • 没有sharedInstance 怎么办?使用 NSNotificationCenter 或类似的东西?
  • @AnthoPak - 在生命周期的某个地方可能有一个sharedInstance
猜你喜欢
  • 1970-01-01
  • 2017-07-22
  • 2020-01-14
  • 1970-01-01
  • 2019-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多