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