#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
上面是我用Logos创建的一个简单的调整。由于某种原因,安装后什么都不起作用,我只是不知道问题是什么,我该如何解决这个问题?
我的其他问题是:
- 既然已经有
SBIconController
类了,为什么我们要声明像SBIconController
这样的类 - 为什么我们将它声明为
NSObject
的子类 - 当我们调用
[SBIconController sharedInstance]
而不是[objc_getClass("SBIconController") sharedInstance]
时,为什么不直接键入SBInController
非常感谢您的帮助!
代码很好。我测试了它(我不使用徽标),当您点击应用程序图标时,确实调用了iconTapped:
方法。但是你想用isEditing
实现什么呢?此属性指示您是否正在编辑SpringBoard(点击并按住应用程序图标),以及当它等于YES
时,点击图标时不会调用iconTapped:
方法。只有当isEditing
等于NO
时才调用它。因此,我建议您插入不带if ([sbic isEditing])
的警报,以测试您的调整是否有效。
至于你的其他问题:
- 在处理私有API时,我们没有头,如果我们尝试使用它们,就会收到警告/错误。在你的情况下,它是
SBIconController
。为了解决这个问题,我们可以下载其他人使用类转储等各种工具转储的头,也可以自己声明这些私有API。在你的情况下是后者 - 因为
SBIconController
继承自NSObject
-
你可以用任何一种方法。当然,当您有类声明时,您不需要使用
objc_getClass
。在你的情况下,你甚至不需要这两样东西。您可以像在任何其他obj-C方法中一样使用self
。您的代码将如下所示:%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