在移动设备的Substrate扩展中使用捆绑资源

3

我将尝试制作一个使用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];

    }

}

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

包已经在正确位置创建,但在启动应用程序后似乎没有创建plist文件。因此,我想说问题应该出现在writeToFile方法或其之前。


writeToFile:atomically:方法有一个返回值,请尝试查看一下。我不确定将FALSE传递给setObject:forKey:是否有效。 - Nate
1个回答

0

您正在尝试将 plist 写入 bundlepath,但未指定文件名。

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


遗憾的是,包仍然是空的。 - junyi00
正确的想法,尽管代码应该是[modsDict writeToFile:path atomically:YES] - Nate

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接