3

I am trying to make a tweak which uses plist file to save some data.
But the app crashes during launch.

Tweak.xm:

#define hackBundlePath @"/Library/MobileSubstrate/DynamicLibraries/testBundle.bundle"

NSMutableDictionary *modsDict = [[NSMutableDictionary alloc] init];

%ctor {

    NSBundle *bundle = [[NSBundle alloc] initWithPath:hackBundlePath];
    NSString *path = [bundle pathForResource:@"HackData" ofType:@"plist"];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath: path]) {
        modsDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
    }
    else {
        [modsDict setObject:FALSE forKey:@"test"];
        [modsDict setObject:FALSE forKey:@"test1"];
        [modsDict setObject:FALSE forKey:@"test2"];

        [modsDict writeToFile:[bundle bundlePath] atomically: TRUE];

    }

}

Makefile:

include theos/makefiles/common.mk

TWEAK_NAME = test
test_FILES = Tweak.xm ModsTableViewController.mm
test_FRAMEWORKS = Foundation UIKit CoreFoundation

include $(THEOS_MAKE_PATH)/tweak.mk

BUNDLE_NAME = testBundle
testBundle_INSTALL_PATH = /Library/MobileSubstrate/DynamicLibraries


include $(THEOS)/makefiles/bundle.mk

The bundle is created at the right location, but after launching the app it seems that the plist file is not created. So I guess I could say the problem should be at the writeToFile method or before it

junyi00
  • 792
  • 3
  • 8
  • 28
  • the `writeToFile:atomically:` method has a return value. Please try looking at that. I'm not 100% sure that passing `FALSE` in to `setObject:forKey:` is valid. – Nate Jul 28 '14 at 22:50

1 Answers1

0

You are trying to write a plist to the bundlepath, not giving it a file name.

[modsDict writeToFile:[[bundle bundlePath] stringByAppendingPathComponent:@"filename.plist"] atomically: YES];

Alex Zielenski
  • 3,591
  • 1
  • 26
  • 44