0
#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]而不是时,为什么不直接输入 SBIconController[objc_getClass("SBIconController") sharedInstance]呢?

非常感谢你的帮助!

4

1 回答 1

1

代码很好。我对其进行了测试(我不使用徽标)并且iconTapped:当您点击应用程序图标时确实调用了方法。但是你想用什么来实现isEditing?此属性指示您是否正在编辑 SpringBoard(点击并按住应用程序图标)以及当点击图标时不调用equalsYES方法。iconTapped:它仅在isEditingequals时调用NO。所以我建议你插入警报而不if ([sbic isEditing])测试你的调整是否有效。

至于你的其他问题:

  1. 在处理私有 API 时,我们没有标头,如果我们尝试使用它们会收到警告/错误。在你的情况下,它是SBIconController. 为了解决这个问题,我们可以下载其他人使用类转储等各种工具转储的标头,也可以自己声明这些私有 API。在你的情况下是后者。
  2. 因为SBIconController继承自NSObject.
  3. 无论哪种方式,你都可以做到。当然,当你有类声明时,你不需要使用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
    
于 2014-01-09T08:06:40.700 回答