0

I am trying to read the BOOL Value from a PSSwitchCell but the BOOL is just coming up true all the time. This is my code (logo tweak (iOSopendev))

This is the .xm file, im using the iosopendev logos tweak template and the simple preference loader.

Also, i know this is just a simple tweak, but i am learning how this all works. I have looked at tutorials online, but i can't seem to see why this is not working.

#import <UIKit/UIKit.h>
#define plist_path @"/Library/PreferenceLoader/Preferences/MyTweak.plist" 

#define listenToNotification$withCallBack(notification, callback);CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)&callback, CFSTR(notification), NULL, CFNotificationSuspensionBehaviorHold);
%hook SBApplicationIcon

+ (id)sharedInstance
{
%log;

return %orig;
}

static NSMutableDictionary *plistDict = nil;
static void loadSettings(void) {
if (plistDict) {
    [plistDict release];
    plistDict = nil;
}
plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plist_path];

}
-(void)launch
{
    NSString *number = [[[plistDict objectForKey:@"enabled"] intValue];

    if ([number isEqualto:@"1"]) {
    NSString *appName = [self displayName];
    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.delegate = self;
    [alert1 show];
    [alert1 release]; }
else {
    //Do nothing!
}
%orig;
}

- (void)messageWithNoReturnAndOneArgument:(id)originalArgument
{
%log;

%orig(originalArgument);

// or, for exmaple, you could use a custom value instead of the original argument: %orig(customValue);
}

- (id)messageWithReturnAndNoArguments
{
    %log;
    id originalReturnOfMessage = %orig;

// for example, you could modify the original return value before returning it:   [SomeOtherClass doSomethingToThisObject:originalReturnOfMessage];

return originalReturnOfMessage;
}

%end
%ctor {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    %init;
    listenToNotification$withCallBack("dylankelly.MyDev.MyTweak-preferencesChanged", loadSettings);
    loadSettings();
    [pool drain];
}

This is my plist (part of it) file, which shows up in settings.

<dict>
    <key>cell</key>
        <string>PSSwitchCell</string>
        <key>default</key>
        <integer>0</integer>
        <key>defaults</key>
        <string>dylankelly.MyDev.MyTweak</string>
        <key>TrueValue</key>
        <integer>1</integer>
        <key>FalseValue</key>
        <integer>0</integer>
        <key>key</key>
        <string>enabled</string>
        <key>label</key>
        <string>Show</string>
        <key>PostNotification</key>
        <string>dylankelly.MyDev.MyTweak-preferencesChanged</string>

</dict>
  • 1
    This is not related to Xcode by any means. And format your code. –  Apr 17 '13 at 16:06
  • Sorry, i have formatted it. – DylanKelly Apr 17 '13 at 16:12
  • 1
    It doesn't look formatted to me. If you want people to help you then you need to make some effort to present your code in a readable form. – Paul R Apr 17 '13 at 16:17
  • Sorry, is that better? – DylanKelly Apr 17 '13 at 16:18
  • @DylanKelly It's better now. –  Apr 17 '13 at 16:19
  • @DylanKelly, I'll repeat my previous comment that you should look into some beginning tutorials first. You are trying to implement advanced tweaks, without a proper iOS foundation. Things like how to load a UIImage from a file, and understanding the basic differences between a BOOL and a NSNumber are fundamentals that all iOS developers (jailbreak or not) need. You can find lots of good sample code at developer.apple.com/ios, or look at iTunes U on iTunes, and have a look at the Stanford University video tutorials. – Nate Apr 17 '13 at 21:03

1 Answers1

1

You can't store a BOOL in a plist or dictionary as it is not an object. Save your values as NSNumbers; @(0) for false and @(1) for true.

You can store the following data types in a .plist file as value:

-NSArray 
-NSMutableArray 
-NSDictionary 
-NSMutableDictionary 
-NSData
-NSMutableData 
-NSString 
-NSMutableString 
-NSNumber 
-NSDate
JonahGabriel
  • 3,066
  • 2
  • 18
  • 28
  • Thanks for the answer! i have changed the plist, and the launch method above, would this work? – DylanKelly Apr 17 '13 at 16:35
  • Give it a shot and let me know :) – JonahGabriel Apr 17 '13 at 16:51
  • it gives an error saying can't initialize a variable of type NSString with a value of type int, on this line NSString *number = [[plistDict objectForKey:@"enabled"] intValue]; – DylanKelly Apr 17 '13 at 16:59
  • i tried just NSString *number = [[plistDict objectForKey:@"enabled"]; which ran fine, but still not working, any ideas? – DylanKelly Apr 17 '13 at 17:03
  • If you are storing the value as an NSNumber, why are you shouldn't it be: NSNumber *number = [[plistDict objectForKey:@"enabled"]; instead of NSString *number? – JonahGabriel Apr 17 '13 at 17:15
  • I honestly did not think about that. Just tried that. Still nothing. Could something be wrong with my linking to the plist file? – DylanKelly Apr 17 '13 at 17:20
  • You can use the debugger to print out the contents of the dictionary to verify if your data is correct. Personally, what I would do is take a dictionary that I know has the correct data and then write that out to disk and then copy it into your bundle. You can look at my answer in the following link for some utility methods for archiving objects: http://stackoverflow.com/questions/15794561/separate-class-for-creating-a-set-of-objects-from-file/15794907#15794907 – JonahGabriel Apr 17 '13 at 17:59
  • Im not sure the debugger would work in this situation, (but im not entirely sure because im new to this) because im using iosopendev then build for profiling on the device, so i don't get any logs, or any feedback from the device when it is running. Im not really sure what you mean, when you say about taking a dictionary that has the correct data etc, sorry where can i get one? thanks! – DylanKelly Apr 17 '13 at 18:06
  • If you are using XCode, you can go to the line you are interested and click on the line number and it will add a breakpoint. You can then go to the inspector window, find your object variable, right click on it and select "Print description of xxx" and it will print out the contents of your dictionary. Use the simulator, not profiling on the device. – JonahGabriel Apr 17 '13 at 18:12
  • So I have put a break point on the if ([number isEqualto:1]) line, now im on the identity inspector on the right, now what do i do? it doesn't open the simulator when i build it, it just says build succeeded, does that matter? – DylanKelly Apr 17 '13 at 18:27
  • If you are using XCode you should be able to choose the simulator in the drop down on the top left of your screen next to the target name. – JonahGabriel Apr 17 '13 at 18:41
  • I selected the simulator, but when it builds on it, nothing happens. – DylanKelly Apr 17 '13 at 18:46