原生集成
远程安装
开始安装
pod init
我们的 SDK 可以使用 CocoaPods 导入。
| SDK | 当前版本 |
|---|---|
| ZaigIosDeviceScan | pod 'ZaigIosDeviceScan', '~> 5.0.1' |
iOS Minimum Deployment Target
15.5
要开始安装,请在项目根目录中执行左侧命令。
在 podfile 中添加 source
source 'https://github.com/ZaigCoding/iOS.git'
下一步是在 podfile 文件中添加 QI Tech source。
在 podfile 中添加 pod
pod 'ZaigIosDeviceScan', '~> <version>'
最后,只需按照上述格式添加 pod 名称即可。
注意:
架构变更(v5.0.0+)从版本 5.0.0 开始,SDK 以纯静态方式分发。在您的 Podfile 中,必须使用 :linkage => :static 配置。
Podfile 示例(版本 5.0.0 或更高)
source 'https://github.com/ZaigCoding/iOS.git'
target 'ExampleApp' do
use_frameworks! :linkage => :static
pod 'ZaigIosDeviceScan', '~> 5.0.0'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if ['DatadogCore', 'DatadogInternal', 'DatadogCrashReporting', 'DatadogLogs'].include?(target.name)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.5'
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
end
Podfile 示例(旧版本)
source 'https://github.com/ZaigCoding/iOS.git'
target 'ExampleApp' do
use_frameworks!
pod 'ZaigIosDeviceScan', '~> 2.0.0'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if ['DatadogCore', 'DatadogInternal', 'DatadogCrashReporting', 'DatadogLogs'].include?(target.name)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.5'
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
end
注意
需要为监控依赖项 'Datadog' 启用模块稳定性,以避免不同 Swift 版本可能存在的编译问题。因此,请将描述的块添加到 Podfile 的 post_install 中(如果已有 post_install 块,则将其包含在现有块中)。
注意
在 iOS 中集成依赖项时,可能需要对某些库使用静态链接,对其他库使用动态链接。此配置对于确保兼容性、避免构建错误和优化项目性能非常重要。
依赖项混合链接(如有需要)
混合链接的 需求是因为某些库有特定要求,有些需要静态链接以避免内部冲突和符号重复,而其他依赖项可能需要动态链接,因为它们是为模块化和项目间共享而设计的。
静态链接与动态链接的区别:
- 静态(static_framework):库代码直接嵌入最终二进制文件,减少运行时加载时间,消除执行时的外部依赖。
- 动态(dynamic_framework):库在运行时作为单独文件加载。这减小了最终二进制文件的大小,便于独立更新/修改。
在 Podfile 中配置混合链接
...
use_frameworks! :linkage => :dynamic # 将默认链接模式配置为动态
...
static_frameworks = ['framework_1', 'framework_2', ...] # 包含所有需要静态链接的依赖项
pre_install do |installer|
installer.pod_targets.each do |pod|
if static_frameworks.include?(pod.name)
def pod.static_framework?;
true
end
def pod.build_type;
Pod::BuildType.static_framework
end
end
end
end
安装依赖项
pod install
最后,执行 pod install 命令下载并安装依赖项。