gpt4 book ai didi

ios - 我无法在 UnitTest 中获取 BundleVersionKey、BundleIdentiferKey

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:33:22 24 4
gpt4 key购买 nike

我为 iOS 应用开发了一个框架。我有一个单元测试用例,用于测试获取 bundleIdentiferKey、bundleVersionKey。

当我运行测试时,它总是失败,因为 Bundle Key 是 nil

我获取 Bundle ID 的逻辑如下。

 NSString * package = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleIdentifierKey];


NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];

我发现只有我的框架源代码中的单元测试用例才nil,但不在我的示例应用中。

我认为这不是问题,因为 UnitTest Target 在 info.plist 中也有一个 bundle Identifier,bundle version

 NSString *version = (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);

version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

这些对我也没有帮助..

我不知道如何解决这个问题。谢谢。

最佳答案

我遇到了类似的问题,并找到了两种可能的解决方法,具体取决于您要尝试做什么。

[NSBundle mainBundle] 替换为 [NSBundle bundleForClass:[self class]] 或在您的单元测试目标中设置主机应用程序。

关于ios - 我无法在 UnitTest 中获取 BundleVersionKey、BundleIdentiferKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37129881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com