在mobilesubtrate tweak中使用bundle资源

时间:2014-07-25 09:20:19

标签: ios cydia theos cydia-substrate

我正在尝试进行调整,使用plist文件来保存一些数据 但该应用程序在发布期间崩溃。

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];

    }

}

生成文件:

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

捆绑包是在正确的位置创建的,但在启动应用程序后,似乎没有创建plist文件。所以我想我可以说问题应该在writeToFile方法或之前

1 个答案:

答案 0 :(得分:0)

您正在尝试将plist写入bundlepath,而不是给它一个文件名。

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

相关问题