跳转至

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 功能的方法,请参阅入门指南