2013-04-21 41 views
0

在我的THEOS调整中,我挂钩了一个类并成功调用了它的一个方法。有条件地调用THEOS/LOGOS中的Hook块内的类

我的问题是,方法名称更改后,我正在调整的应用程序的更新。

在旧版本中,所讨论的方法带有一个参数(方法:arg1),然后它得到更新以获得2个参数(方法:arg1:arg2)。 现在我的代码看起来像这样

%hook className 

- (void)method:arg1 { 
    // 
} 

- (void)method:arg1:arg2 { 
    // 
} 

%end 

这种设置能正常工作在新的版本,但会导致应用程序在老版本崩溃。 有没有一种方法可以根据bundle版本([[NSBundle mainBundle] objectForInfoDictionaryKey:@“CFBundleVersion”])有条件地调用这些方法之一?

我玩过#if和#endif,但没有太远。

您的帮助非常感谢。

回答

0

如果endif是宏编译时,而不是像你需要的运行时。

我也在学习theos标志,但我认为你应该使用%group和%ctor {}作为条件。

在这里看到:How do I use the %group feature in Theos/Logos?

+0

感谢您抽出时间来回答。 我已经找到了答案,并查看了一些现有的开源“tweak.mm”文件,以查看其他人是如何使用它的。但从来没有回答我自己的问题。 – boudarbalat 2013-05-13 11:58:16

0

干杯

%group A 
 
%hook className 
 

 
- (void)method:arg1 { 
 
    // 
 
} 
 

 
%end 
 
%end 
 
%group B 
 
%hook className 
 

 
- (void)method:arg1:arg2 { 
 
    // 
 
} 
 

 
%end 
 
%end 
 
%ctor{ 
 
if([anObject respondsToSelctor:@selector(method:arg1:arg2)]){ 
 
%init(B) 
 

 
} 
 
else{ 
 
%init(A) 
 
}