[英]Can I read my app extension's info.plist in my host app?
I've built a today widget and I want to show what version is running in my host app's about screen. 我已经构建了一个今天的小部件,我想显示我的主机应用程序中关于屏幕的版本。 Is there a way to do that?
有没有办法做到这一点?
I've tried replacing [NSBundle mainBundle]
with bundleWithIdentifier
but that fails. 我试着更换
[NSBundle mainBundle]
与bundleWithIdentifier
但失败了。 So, is there a way to get the infoDictionary
from he extension bundle, or am I wasting my time? 那么,有没有办法从他的扩展包中获取
infoDictionary
,还是我在浪费时间?
You can pull this off by specifying the direct path to the extension's bundle. 您可以通过指定扩展程序包的直接路径来关闭它。 It looks like app extensions live in the
PlugIns/
folder in your app's main bundle. 看起来app扩展程序位于应用程序主包中的
PlugIns/
文件夹中。 You can create an instance of NSBundle
by using -initWithPath:
. 您可以使用
-initWithPath:
创建NSBundle
的实例。 For example: 例如:
- (NSBundle *)appExtensionBundle {
NSString *plugInsPath = [NSBundle mainBundle].builtInPlugInsPath;
NSString *appExtensionPath = [plugInsPath stringByAppendingPathComponent:@"MyTodayExtension.appex"];
return [[NSBundle alloc] initWithPath:appExtensionPath];
}
NOTE: This code was tested only with a Today extension. 注意:此代码仅在Today扩展中进行了测试。 You should test to make sure it works correctly if you have other types of extensions.
如果您有其他类型的扩展,则应进行测试以确保其正常工作。
You can't. 你不能。 Application and Extension cant access each others code and address space.
应用程序和扩展程序无法访问彼此的代码和地址空间。 They can only share data using Sharing the container using AppGroup or by using Shared NSUserDefault.
他们只能使用AppGroup共享容器或使用Shared NSUserDefault来共享数据。
Using both the approach will require to run your extension atleast once. 使用这两种方法都需要至少运行一次扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.