我的调整没有执行

My Tweak Isn't Executing

编辑:

10 个小时的调试,我转向 SO。

这段代码显然有问题,我不知道是什么原因造成的。我在 ChineseSkill 应用程序中挂接了 TestOut 视图,但是当我进入该视图时,它的行为就好像原始应用程序没有任何变化一样。

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface TestOutViewController : UIViewController <UIAlertViewDelegate>
- (UIButton *)quitButton;
@end

%hook TestOutViewController

- (void)viewDidAppear:(BOOL)view {
    %orig;

    UIButton *infiniteLivesButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [infiniteLivesButton setTitle:@"Infinite Lives" forState:UIControlStateNormal];
    [infiniteLivesButton setFrame:CGRectMake(/*[self quitButton].frame.origin.x + [self quitButton].frame.size.width, [self quitButton].frame.origin.y + 20*/50, 50, 200, 50)];
    [infiniteLivesButton setBackgroundColor:[UIColor redColor]];
    [infiniteLivesButton addTarget:self
        action:@selector(makeLivesInfinite:)
        forControlEvents:UIControlEventTouchUpInside];

    UIButton *passTestButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [passTestButton setTitle:@"Skip Test" forState:UIControlStateNormal];
    [passTestButton setFrame:CGRectMake(infiniteLivesButton.frame.origin.x + infiniteLivesButton.frame.size.width + 10,
                                        infiniteLivesButton.frame.origin.y,
                                        150,
                                        50)];
    [passTestButton addTarget:self
        action:@selector(skipTest:)
        forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:passTestButton];
    [self.view addSubview:infiniteLivesButton];

    UIAlertView *successAlertView = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Infinite hearts for the rest of this test." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [successAlertView show];
}

- (void)touchesBegan:(id)began withEvent:(id)event {
    UIAlertView *testView = [[UIAlertView alloc] initWithTitle:@"Test" message:@"Test Alert" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [testView show];
}

%new
- (void)makeLivesInfinite:(UIButton *)sender {
    [self performSelector:@selector(setNNumberofLeftHearts:) withObject:@1000000];
    UIAlertView *successAlertView = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Infinite hearts for the rest of this test." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [successAlertView show];
}

%new
- (UIButton *)quitButton {
    return objc_getAssociatedObject(self, @selector(quitButton));
}

%new
- (void)skipTest:(UIButton *)sender {
    [self performSelector:@selector(setNTotalTest:) withObject:@1];
    [self performSelector:@selector(CheckOrContinueButtonClick:) withObject:NULL];
    [self performSelector:@selector(CheckOrContinueButtonClick:) withObject:NULL];
}

%end

没有警告视图,没有添加视图,什么都没有。几乎任何事情都会有所帮助。

您的问题是您必须在调整的 plist 文件中设置正确的过滤器。默认情况下,plist 文件有一个包标识符过滤器 com.apple.springboard。您应该将其更改为您要注入代码的应用程序的包标识符。

更多信息(一点点):

后面发生了什么? MobileLoader 负责将您的代码修补到程序中。这些 plist 文件告诉 MobileLoader 在哪个程序、哪个框架或哪个 运行 进程中修补代码。所以你的进程是应用程序而不是 SpringBoard。这个link 关于CydiaSubstrate (MobileSubstrate) 有很好的解释。你也可以看看它的文档。