多平台cocoapods库配置

问题描述 投票:0回答:1

我有一套iOS,MacOS,WatchOS和TvOS的片段,我想嵌入Cocoapod库(也可能支持Carthage)。

对我来说棘手的部分是我有所有平台(iOS,MacOS TvOS等)的目标,但有些文件只针对它们的一部分。

在我的Xcode项目中,我将代码分成以下文件夹:

  • Library_Common(目标全部)
  • Library_iOS(目标iOS)
  • Library_WatchOS(目标WatchOS)
  • Library_MacOS(目标MacOS)

这是因为,例如,库的iOS部分可能需要UIKit,而MacOS可能需要其他不适用于iOS的框架。

如何设置podspec以使该库可以嵌入所有平台?

有没有办法做到这一点,或者最好将它拆分到不同的库中?这种方法的问题是每个人都会重复Library_Common部分。

ios macos cocoapods tvos watch-os
1个回答
0
投票

我终于找到了我想要的东西,似乎在podspec文档本身中指定。不幸的是我以前没见过:

https://guides.cocoapods.org/syntax/podspec.html#group_multi_platform_support

这意味着,在我的情况下,我有以下设置:

s.source_files  = "MyLibrary_common/**/*.{h,m}"
s.ios.source_files = "MyLibrary_iOS/**/*.{h,m}"
s.osx.source_files = "MyLibrary_macOS/**/*.{h,m}"
s.tvos.source_files = "MyLibrary_tvOS/**/*.{h,m}"
s.watchos.source_files = "MyLibrary_watchOS/**/*.{h,m}"
© www.soinside.com 2019 - 2024. All rights reserved.