Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

ios - 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? i.e. LSSupportsOpeningDocumentsInPlace = NO for iOS and LSSupportsOpeningDocumentsInPlace = YES for macOS


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

enter image description here

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:

enter image description here

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

enter image description here

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

enter image description here

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:

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...