ios - 我可以在我的主机应用程序中读取我的应用程序扩展的 info.plist 吗?

标签 ios ios8-today-widget today-extension

我构建了一个今日小部件,我想在我的主机应用程序的“关于”屏幕中显示正在运行的版本。有没有办法做到这一点?

我尝试用 bundleWithIdentifier 替换 [NSBundle mainBundle] 但失败了。那么,有没有办法从他的扩展包中获取 infoDictionary,或者我是在浪费时间吗?

最佳答案

您可以通过指定扩展包的直接路径来实现这一点。看起来应用程序扩展存在于应用程序主包的 PlugIns/ 文件夹中。您可以使用 -initWithPath: 创建 NSBundle 的实例。例如:

- (NSBundle *)appExtensionBundle {
    NSString *plugInsPath = [NSBundle mainBundle].builtInPlugInsPath;
    NSString *appExtensionPath = [plugInsPath stringByAppendingPathComponent:@"MyTodayExtension.appex"];
    return [[NSBundle alloc] initWithPath:appExtensionPath];
}

注意:此代码仅使用 Today 扩展进行了测试。如果您有其他类型的扩展程序,您应该测试以确保它能正常工作。

关于ios - 我可以在我的主机应用程序中读取我的应用程序扩展的 info.plist 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29611963/

相关文章:

ios - 如何使用 UIPanGestureRecognizer move 2 个或更多 UIImageViews

ios - 应用内购买 : request products randomly get some valid product and some invalid products?

ios - 在今天的扩展中,我如何从主应用程序获取数据?

iOS - sharedApplication 在 Today Extension 中不可用?

ios - 复制 iOS kCGBlendModeSoftLight 混合

ios - 从 Swift 函数中的异步调用返回数据

ios - 今天 iPad 的扩展高度比指定的要大得多

ios - 从通知中心启动应用程序时发生奇怪的崩溃

iOS Today Extension 在 iPhone 上不断崩溃,而不是在模拟器中

ios - 使用 Swift 在 Today Extension(小部件)中显示警报