iosobjective-ccydia-substrate

Why does my Tweak Not work Correctly?


I am making my First MobileSubstrate Tweak For the iPhone Running IOS 7.

I am using this tutorial.

This tutorial explains the basics of Hooking and providers a git hub example of his source code.

To test the code he wrote worked and to get my head round theos compiling terminal I compiled his project.

The project is suppose to show a UIAlert when an application is launched and put a setting switching with the state of on or off within the settings application in the iPhone.

When installing this compiled deb onto my iphone the setting page is added so i can turn the function on or off but when the function is ON the alert does not show.

Here is my Tweak.xm code:

@interface SBApplicationIcon
-(void)launch;
-(id)displayName;
@end

%hook SBApplicationIcon
-(void)launch
{
    NSString *appName = [self displayName];

    NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithContentsOfFile:
                                    [NSString stringWithFormat:@"%@/Library/Preferences/%@", NSHomeDirectory(), @"com.AndyIbanez.NotifierSettings.plist"]];
    NSNumber* shouldNotify = [settings objectForKey:@"alertLaunch"];

    if([shouldNotify boolValue] == YES)
    {
        NSString *message = [NSString stringWithFormat:@"The app %@ has been launched", appName, nil];
        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:appName message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert1 show];
        [alert1 release];
    }
    %orig;
}
%end

Here is the GitHub Example File I am following and compelling: https://github.com/AndyIbanez/TutorialProjects/tree/master/launchnotifier


Solution

  • launch is for iOS 6 and you need to use launchFromLocation: on iOS 7.

    @interface SBIcon : NSObject
    - (void)launch; // iOS 6
    - (void)launchFromLocation:(NSInteger)location; //iOS 7
    @end