跳轉至

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。