【问题标题】:Using bundle resource in mobilesubtrate tweak在 mobilesubtrate 调整中使用捆绑资源
【发布时间】:2014-07-25 09:20:18
【问题描述】:

我正在尝试使用 plist 文件来保存一些数据。
但应用在启动时崩溃。

调整.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 方法或之前

【问题讨论】:

  • writeToFile:atomically: 方法有一个返回值。请尝试查看。我不能 100% 确定将 FALSE 传递给 setObject:forKey: 是否有效。

标签: ios cydia theos cydia-substrate


【解决方案1】:

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

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

【讨论】:

  • 遗憾的是,bundle 还是空的
  • 正确的想法,虽然代码应该是[modsDict writeToFile: path atomically: YES]
猜你喜欢
  • 2021-05-08
  • 2016-12-30
  • 2016-03-15
  • 2016-11-16
  • 1970-01-01
  • 2015-11-24
  • 1970-01-01
  • 2012-12-04
相关资源
最近更新 更多