我正在开发一个在 iOS 和 macOS(Catalyst) 上运行的应用程序。该应用程序支持打开文档。
我已在 info.plist 中将 LSSupportsOpeningDocumentsInPlace 的值声明为 NO,但这不会为 mac Catalyst 目标构建。构建错误显示“macOS 不支持‘LSSupportsOpeningDocumentsInPlace = NO’。删除该条目或将其设置为 YES,并确保应用程序确实在 macOS 上打开文档。” 但此应用程序不处理原始文档,它需要复制文档。
那么有没有办法可以在 info.plist 中为 iOS 和 macOS 设置不同的值?即对于 iOS,LSSupportsOpeningDocumentsInPlace = NO;对于 macOS,LSSupportsOpeningDocumentsInPlace = YES
有不同的方法可以以不同程度的灵活性来解决这个问题。
密钥的构建设置中引用的 Catalyst 的完全自定义 Info.plist INFOPLIST_FILE。只需单击每个构建配置(通常是调试和发布)旁边的 + 即可添加特定 SDK 的覆盖,然后选择“任何 macOS SDK”。这样您就可以省略自定义 Info.plist 中的键并依赖默认值。如果默认值发生变化,您将免费获得它。
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.
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
Run Code Online (Sandbox Code Playgroud)
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.
| 归档时间: |
|
| 查看次数: |
1030 次 |
| 最近记录: |