简体   繁体   English

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

[英]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.

相关问题 Flutter/iOS:如何在 NotificationServiceExtension Info.plist 文件中使用 pubspec.yaml 的 App 版本? - Flutter/iOS: How can I use pubspec.yaml's App version in my NotificationServiceExtension Info.plist file? 是否可以在iOS中读取已安装应用的info.plist? - Is it possible to read an installed app's info.plist in iOS? 当我在我的应用程序中使用 Mapbox sdk 时,无法从文件中读取属性列表,Info.plist 问题 - unable to read property list from file, Info.plist issue when I use Mapbox sdk in my app 如何从我的iPhone应用程序的config.xml文件中的info.plist中读取密钥的值 - How to read the value for a key from the info.plist in an config.xml file in my iPhone app iOS应用无法读取info.plist - iOS app cannot read info.plist 如何将 NSAppTransportSecurity 添加到我的 info.plist 文件中? - How can I add NSAppTransportSecurity to my info.plist file? MessageExtension 应用程序使用说明错误,但我的 Info.plist 中有密钥 - MessageExtension App usage description error but I have the key in my Info.plist iOS:我配置了info.plist,但它不适用于我的应用程序,但是我配置了目标信息,但对我却有效 - iOS:I config my info.plist it did not work for my app,but I config the Target Info, it work for me 应用程序因Info.plist文件麦克风中缺少目的字符串而被拒绝,但我无法在info.plist中添加说明 - App got rejected for missing Purpose String in Info.plist File Microphone, but I can't add the description in info.plist 'my_app.app/ResearchKit/ResearchKit/Info.plist'中的包不包含可执行包 - The bundle at 'my_app.app/ResearchKit/ResearchKit/Info.plist' does not contain a bundle executable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM