简体   繁体   中英

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). 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." 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? ie LSSupportsOpeningDocumentsInPlace = NO for iOS and LSSupportsOpeningDocumentsInPlace = YES for macOS

There are different ways to solve this with different levels of flexibility.

1. Custom Info.plist for Catalyst

A completely custom Info.plist for Catalyst referenced in Build Settings for the INFOPLIST_FILE key. 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'. That way you could omit the key in the custom Info.plist and rely on the default value. If the default value should ever change, you'll get this for free.

在此处输入图像描述

2. Custom User-Defined key

Reference a custom User-Defined key from Build Settings in your Info.plist. Go to Build Settings and tap the + button and choose 'Add User-Defined Setting' at the very top next to Basic/Customized/All | 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':

在此处输入图像描述

Now, hop over to the Info.plist and use your custom key embedded in a $() as the value for the LSSupportsOpeningDocumentsInPlace key:

在此处输入图像描述

Note: Even though it's a Boolean the value type is string .

3. Use xcconfig files

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. 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:

在此处输入图像描述

In the config file you can define a key value pair and override the value for specific SDKs like this:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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