跳转至

iOS Native - CocoaPods

iOS Native 安装指南(CocoaPods)

本文档说明如何将 Hercules 添加到**已使用 CocoaPods 的 iOS 项目**中。

  • 由于 CocoaPods 停止维护,未来可能与新版 Xcode 出现兼容性问题,因此建议使用 SPM。

Hercules Spec 仓库:

https://github.com/Com2uSPlatformCorp/Hercules-iOS


1. 将 Hercules Spec 仓库添加到 Podfile

在现有 Podfile 的 source 配置中添加 Hercules 仓库。

示例:

source 'https://github.com/Com2uSPlatformCorp/Hercules-iOS.git'
Warning

请注意不要移除现有的 source。


2. 添加 Hercules

选择版本,并在 target 内添加 Hercules 条目。 本指南指定使用 26.8.31 版本。

示例:

$HERCULES_VERSION = '26.8.31'

target 'GameApp' do
  # 现有的 Pods
  pod '库 1'
  pod '库 2'

  # 在此添加 Hercules
  pod 'Hercules', $HERCULES_VERSION
end
Warning

请注意不要移除上下方的现有内容。


3. 安装 Pod

在项目的 Podfile 所在目录中执行以下命令。

pod install --repo-update

4. 更改版本

要更改 Hercules 版本,只需修改 Podfile 中的 $HERCULES_VERSION 变量。

示例:

$HERCULES_VERSION = '26.8.31'

在项目的 Podfile 所在目录中执行以下命令。

pod update Hercules --repo-update

5. 查看已安装的版本

可在 Podfile.lock 中查看当前项目已安装的 Hercules 版本。

示例:

PODS:
  - Hercules (26.8.31)

6. 使用 API

Objective-C / Objective-C++

使用 .xsworkspace 打开项目,并包含 Hercules.h 头文件以使用 API。

示例:

#import <Hercules/Hercules.h>
...
unsigned int version = HerculesGetVersion();
NSLog(@"Hercules version: %u", version);

初始化会在 Hive SDK 初始化时自动执行。

无需单独调用 InitializeHercules。