viewDidLoad
in the app to show a UIAlertView, but nothing happened. Does anyone have idea what could cause the tweak to compile but not run properly?10 hours of debugging, I'm turning to SO.
There's obviously something wrong with this code, and I have no idea what could be causing it. I'm hooking the TestOut view in the ChineseSkill app, but when I get to the view it acts as if nothing changed from the original app.
#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
There's no alert views, no added views, no nothing. Nearly anything will help.
Your problem is you have to set the right filters in your tweak's plist file. By default the plist file has a bundle identifier filter com.apple.springboard
. You should change this to the bundle identifier of the app you want your code injected.
Furthur information (Just a little):
What is happening in behind? MobileLoader
is responsible for patching your code into a program. These plist files tell MobileLoader to patch the code in which program(s), in which framework(s) or in which running process. So your process is the app and not SpringBoard
. This link
has good explanation about CydiaSubstrate (MobileSubstrate). You could also have a look at its documentation.