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