Praxder
Praxder

Reputation: 2759

How is this working? - Jailbreak Tweak

I am very new to jailbroken iOS tweak development and had a question. I followed a tutorial to make an alert appear whenever an app is opened from Springboard. The tweak code is:

#include <UIKit/UIKit.h>
@interface SBApplicationIcon
- (void)launchFromLocation:(int)arg;
- (id)displayName;
@end

%hook SBApplicationIcon

-(void)launchFromLocation:(int)location{

        NSString *appName = [self displayName];
        NSString *message = [NSString stringWithFormat:@"Application launched: %@", appName];
        UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:appName message:message delegate:nil cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
        [myAlert show];

    %orig;
}//end function

%end

And this tweak code works just fine. What I don't understand is how this is working. Looking at the header file for SBApplicationIcon, there is no such method as -(void)launchFromLocation:(int)location;

After some research though I found that the SBIcon class header has this exact function definition. If I change the code to:

#include <UIKit/UIKit.h>
@interface SBIcon
- (void)launchFromLocation:(int)arg;
- (id)displayName;
@end

%hook SBIcon

-(void)launchFromLocation:(int)location{

        NSString *appName = [self displayName];
        NSString *message = [NSString stringWithFormat:@"Application launched: %@", appName];
        UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:appName message:message delegate:nil cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
        [myAlert show];

    %orig;
}//end function

%end

The alert view doesn't appear and the function is never called! I feel like this is a stupid question, but I simply don't understand how this is working. Can someone please explain it to me? I am using iOS7 headers and an iOS7 iPhone.

Thanks!

Upvotes: 1

Views: 795

Answers (1)

Aehmlo
Aehmlo

Reputation: 930

SBIcon's -launch method (since at least iOS 5, don't know about earlier) has always existed simply to be overridden in subclasses such as SBLeafIcon, the superclass of SBApplicationIcon. This is also true of -launchFromLocation: in iOS 7. As such, SBIcon's implementation of it is never called (why call through to super if it's just an empty method?), so your code never runs if you hook SBIcon.

Upvotes: 1

Related Questions