跳轉至

iOS

本指南說明如何使用 CocoaPods 或 Swift Package Manager (SPM) 安裝 Hive SDK 功能。

使用 CocoaPods

修改 Xcode 專案目錄中的 Podfile,以將 Hive SDK 功能作為框架添加。在這裡,我們通過僅使用 Google 認證和 Apple AppStore 付款 作為範例來指導您。

選擇要使用的功能

將 Google 認證和 Apple AppStore 付款框架添加到專案目錄中的 Podfile。

pod 'HiveAuthV4ProviderGoogle', $HIVE_SDK_VERSION # Use Google IdP login for authentication (authv4)
pod 'HiveIAPV4', $HIVE_SDK_VERSION # Use appstore in-app purchases for payment (iapv4)

以下是 Podfile 的完整範例,包括安裝 Hive SDK,當上述框架被添加時。有關更詳細的資訊,請參閱框架安裝後產生的 Podfile.lock 文件。

source 'https://github.com/CocoaPods/Specs.git'
# Add Hive SDK repository as a source
source 'https://github.com/Com2uSPlatformCorp/HiveSDK-iOS'

platform :ios, '12.0'
use_frameworks!
inhibit_all_warnings!

$HIVE_SDK_VERSION = '24.1.0' # Hive SDK version

project 'HIVE_SDK_Sample_App.xcodeproj'

target 'HIVE_SDK_Sample_App' do
   pod 'HiveAuthV4ProviderGoogle', $HIVE_SDK_VERSION # Use Google IdP login for authentication (authv4)
   pod 'HiveIAPV4', $HIVE_SDK_VERSION # Use appstore in-app purchases for payment (iapv4)
end

post_install do |installer|
 installer.pods_project.targets.each do |target|
   target.build_configurations.each do |config|
     # Change the iOS target of each framework to 12 if it is below 12
     if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 12.0
       config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
     end
     # Address xcode 15 TOOLCHAIN_DIR related compile error issue
     xcconfig_path = config.base_configuration_reference.real_path
     xcconfig = File.read(xcconfig_path)
     xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
     File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
   end
 end
end

在保存包含上述添加框架的 Podfile 後,執行以下命令以在專案中安裝框架。

pod install

附加設定

這是安裝 Hive SDK 功能所需的附加設置指南。

Google IdP 設定

這是設置 Google IdP 的指南。請按照以下說明在 Xcode 專案中輸入反向客戶端 ID。

  1. Xcode專案窗口的專案導航器中選擇您的專案。
  2. TARGETS列表中選擇您的應用程式。
  3. 點擊Info標籤。
  4. 在Info標籤中點擊URL類型部分,然後點擊+圖標以創建額外的URL類型屬性。
  5. 在額外的URL類型屬性下,保持Identifier字段為空,並在URL Schemes字段中輸入反向客戶端ID。
Info

有關每個 Hive SDK 功能(身份驗證、計費、通知等)的詳細資訊,請參閱各自的功能指南。

使用 Swift Package Manager (Beta)

有關使用 Swift Package Manager (SPM) 添加 Hive SDK 功能的方法,請參閱入門指南