简单的iPhone越狱调整不工作
题
#import <UIKit/UIAlertView.h>
@class NSObject;
@interface SBIconController : NSObject
+ (SBIconController *)sharedInstance;
- (BOOL)isEditing;
@end
%hook SBIconController
-(void)iconTapped:(id)tapped {
SBIconController *sbic = [objc_getClass("SBIconController") sharedInstance];
if ([sbic isEditing]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message" message:[NSString stringWithFormat:@"%@", tapped] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
%orig;
}
%end
上面是我用徽标创建的一个简单的调整。由于安装后的某种原因,没有任何工作,我只是无法弄清楚问题是什么,我该如何解决这个问题?
我有其他问题是:
- 为什么我们这样声明类
SBIconController
当已经有一个SBIconController
上课? - 为什么我们将其声明为
NSObject
? - 当我们调用
[SBIconController sharedInstance]
而不是[objc_getClass("SBIconController") sharedInstance]
?
非常感谢您的帮助!
解决方案
代码很好。我测试了它(我不使用徽标)和 iconTapped:
当您点击应用程序图标时,确实会调用方法。但你想用什么来实现呢? isEditing
?此属性指示您是否正在编辑SpringBoard(点击并按住应用程序图标)以及何时等于 YES
方法 iconTapped:
点击图标时不调用。只有当它被称为 isEditing
平等 NO
.所以我建议你插入警报没有 if ([sbic isEditing])
测试你的调整是否有效。
至于你的其他问题:
- 在处理私有Api时,我们没有标头,如果我们尝试使用它们,会得到警告/错误。在你的情况下,它是
SBIconController
.为了解决这个问题,我们可以下载其他人使用类转储等各种工具转储的头文件,或者自己声明这些私有Api。在你的情况下,它是后者。 - 因为
SBIconController
继承自NSObject
. 你可以做到这两种方式。当然,当你有类声明时,你不需要使用
objc_getClass
.在你的情况下,你甚至不需要这些东西。你可以用self
就像你在任何其他obj-C方法中一样。您的代码将如下所示:%hook SBIconController -(void)iconTapped:(id)tapped { if ([self isEditing]) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message" message:[NSString stringWithFormat:@"%@", tapped] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release]; } %orig; } %end
不隶属于 StackOverflow