简体   繁体   English

为 mac 催化剂的 info.plist 文件中的键设置不同的值

[英]Set different value to key in info.plist file for mac catalyst

I'm working on an app that runs on both iOS and macOS(Catalyst).我正在开发一个在 iOS 和 macOS(Catalyst) 上运行的应用程序。 This app supports opening documents.这个应用程序支持打开文档。

I've declared value of LSSupportsOpeningDocumentsInPlace to NO in info.plist but this won't build for mac catalyst target.The build error says "'LSSupportsOpeningDocumentsInPlace = NO' is not supported on macOS. Either remove the entry or set it to YES, and also ensure that the application does open documents in place on macOS."我已经在 info.plist 中将 LSSupportsOpeningDocumentsInPlace 的值声明为 NO,但这不会为 mac 催化剂目标构建。构建错误说“macOS 不支持'LSSupportsOpeningDocumentsInPlace = NO'。删除条目或将其设置为是,并确保应用程序确实在 macOS 上打开文档。” But This app doesn't handle the original document, it needs the document to be copied instead.但是这个应用程序不处理原始文档,它需要复制文档。

So is there a way where I can set a different value for iOS and macOS in info.plist?那么有没有一种方法可以在 info.plist 中为 iOS 和 macOS 设置不同的值? ie LSSupportsOpeningDocumentsInPlace = NO for iOS and LSSupportsOpeningDocumentsInPlace = YES for macOS即 LSSupportsOpeningDocumentsInPlace = NO 对于 iOS 和 LSSupportsOpeningDocumentsInPlace = YES 对于 macOS

There are different ways to solve this with different levels of flexibility.有不同的方法以不同程度的灵活性来解决这个问题。

1. Custom Info.plist for Catalyst 1. Catalyst 的自定义 Info.plist

A completely custom Info.plist for Catalyst referenced in Build Settings for the INFOPLIST_FILE key.INFOPLIST_FILE键的构建设置中引用的 Catalyst 的完全自定义 Info.plist。 Just click on the + next to each build configuration (usually Debug and Release) to add an override for a specific SDK and choose 'Any macOS SDK'.只需单击每个构建配置(通常是调试和发布)旁边的 + 以添加特定 SDK 的覆盖并选择“任何 macOS SDK”。 That way you could omit the key in the custom Info.plist and rely on the default value.这样,您可以省略自定义 Info.plist 中的键并依赖默认值。 If the default value should ever change, you'll get this for free.如果默认值应该更改,您将免费获得此值。

在此处输入图像描述

2. Custom User-Defined key 2.自定义用户自定义键

Reference a custom User-Defined key from Build Settings in your Info.plist.从 Info.plist 中的 Build Settings 引用自定义的用户定义键。 Go to Build Settings and tap the + button and choose 'Add User-Defined Setting' at the very top next to Basic/Customized/All | Go 以构建设置并点击 + 按钮并在基本/自定义/全部旁边的最顶部选择“添加用户定义的设置”| Combined/Levels:组合/级别:

在此处输入图像描述

Use a custom key that sounds similar to the key you want to provide a platform dependent value for and use the same trick as mentioned above to override the value for 'Any macOS SDK':使用听起来与您要为其提供平台相关值的键相似的自定义键,并使用与上述相同的技巧来覆盖“任何 macOS SDK”的值:

在此处输入图像描述

Now, hop over to the Info.plist and use your custom key embedded in a $() as the value for the LSSupportsOpeningDocumentsInPlace key:现在,跳到 Info.plist 并使用嵌入在$()中的自定义键作为LSSupportsOpeningDocumentsInPlace键的值:

在此处输入图像描述

Note: Even though it's a Boolean the value type is string .注意:即使它是 Boolean,值类型也是string

3. Use xcconfig files 3.使用xcconfig文件

If you already use xcconfig files to manage your build settings in a git friendly format you can also use this to define your custom values.如果您已经使用 xcconfig 文件以 git 友好格式管理您的构建设置,您也可以使用它来定义您的自定义值。 Assuming you have a single Config.xcconfig file for both Debug and Release (or all your build configs in general), make sure they are used for your target by selecting them from the project's Info screen:假设您有一个 Config.xcconfig 文件用于 Debug 和 Release(或所有通常的构建配置),请通过从项目的 Info 屏幕中选择它们来确保它们用于您的目标:

在此处输入图像描述

In the config file you can define a key value pair and override the value for specific SDKs like this:在配置文件中,您可以定义一个键值对并覆盖特定 SDK 的值,如下所示:

CUSTOM_LS_SUPPORTS_OPENING_DOCUMENTS_IN_PLACE = NO
CUSTOM_LS_SUPPORTS_OPENING_DOCUMENTS_IN_PLACE[sdk=macosx*] = YES

Hop over to the build settings and scroll to the very bottom.跳到构建设置并滚动到最底部。 You should see the key value pair in the same User-Defined section as the one defined in option 2. Using the value is also equivalent, so just make sure to use the correct key in the Info.plist.您应该在与选项 2 中定义的相同的用户定义部分中看到键值对。使用该值也是等效的,因此请确保在 Info.plist 中使用正确的键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM