ข้ามไปที่เนื้อหา

iOS

คู่มือนี้อธิบายวิธีการติดตั้ง SDK ของแบรนด์ Hive สำหรับ iOS โดยใช้ CocoaPods.

การใช้งาน CocoaPods

เพิ่มที่เก็บ Hive SDK

เพิ่มที่เก็บ SDK ของ Hive เป็นแหล่งข้อมูลใน Podfile ที่สร้างขึ้น

source 'https://github.com/Com2uSPlatformCorp/HiveSDK-iOS'

เพิ่ม SDK ลงในโปรเจกต์ Xcode

แก้ไข Podfile ในไดเรกทอรีโปรเจกต์ Xcode เพื่อเพิ่ม Hive SDK

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

$HIVE_SDK_VERSION = '26.1.0'                    # เวอร์ชัน SDK ที่จะใช้
$IOS_DEPLOYMENT_TARGET_VERSION = '13.0'         # เวอร์ชัน iOS ขั้นต่ำที่เกมรองรับ
$IOS_DEPLOYMENT_MINIMUM_TARGET_VERSION = '13.0' # เวอร์ชัน iOS ขั้นต่ำที่ SDK รองรับ (ดู release notes ของเวอร์ชัน SDK ที่ใช้)

platform :ios, $IOS_DEPLOYMENT_TARGET_VERSION
use_frameworks!
inhibit_all_warnings!

project 'HIVE_SDK_Sample_App.xcodeproj'

target 'HIVE_SDK_Sample_App' do
  # Add the frameworks to use here. At least one framework is required.
  # Example: Add the following framework when using Google IdP login in Hive SDK authentication
  pod 'HiveAuthV4ProviderGoogle', $HIVE_SDK_VERSION # When using Google IdP login for authentication (authv4)
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
     target.build_configurations.each do |config|
     # เปลี่ยน iOS target ของแต่ละ framework เป็น 15 หากต่ำกว่า 15
     if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < $IOS_DEPLOYMENT_MINIMUM_TARGET_VERSION.to_f
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = $IOS_DEPLOYMENT_MINIMUM_TARGET_VERSION.to_f
     end
     # Handle xcode 15 TOOLCHAIN_DIR related compile error issues
     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

การใช้งาน Swift Package Manager (Beta)

คู่มือนี้อธิบายวิธีการติดตั้ง iOS SDK โดยใช้ Swift Package Manager (SPM)

  1. เลือกเมนูเพิ่มแพ็กเกจในโปรเจกต์ Xcode

    Unity

    หากคุณติดตั้ง Hive SDK ในสภาพแวดล้อม Unity แล้วบิลด์โปรเจกต์ Xcode และ pod install ได้ถูกรันไปแล้วโดยอัตโนมัติ คุณต้องรันคำสั่ง pod deintegrate ก่อน

  2. ค้นหาที่เก็บแพ็กเกจ Hive SDK และระบุเวอร์ชัน

    1. ป้อนที่อยู่ต่อไปนี้ใน 1

      https://github.com/Com2uSPlatformCorp/HiveSDK-iOS-SPM
      
    2. เลือก Exact Version ใน 2 แล้วป้อนเวอร์ชัน SDK ที่ต้องการใช้

    3. คลิก 3

  3. เมื่อโหลดแพ็กเกจเสร็จและรายการผลิตภัณฑ์ปรากฏขึ้น ให้นำผลิตภัณฑ์ Hive SDK ที่ต้องการ (Authentication, Billing, Analytics ฯลฯ) ไปใช้กับ app target

    Warning

    ผลิตภัณฑ์ Hive SDK ต่อไปนี้ไม่รองรับ SPM และต้องเพิ่มผ่าน CocoaPods

    • HerculesSwift
    • HiveAuthV4ProviderQQ
    • HiveAuthV4ProviderLine
    • HiveAuthV4ProviderWechat
    • HiveAnalyticsProviderAirbridge

    เขียน pod syntax สำหรับสิ่งเหล่านี้ใน Podfile แล้วรัน pod install อย่าลืมว่าผลิตภัณฑ์ Hive SDK ที่ใช้ SPM ไปแล้วไม่ควรรวมอยู่ด้วย หากมี dependencies เพิ่มเติมที่ต้องการใช้ ก็สามารถเพิ่มผ่าน CocoaPods ได้เช่นกัน

    Unity

    หากคุณติดตั้ง Hive SDK ในสภาพแวดล้อม Unity แล้วสร้างโปรเจกต์ Xcode ให้นำผลิตภัณฑ์ Hive SDK ไปใช้กับ target UnityFramework แทนที่จะเป็น app target อย่างไรก็ตาม ผลิตภัณฑ์ Hive_AuthV4ProviderFacebook และ Hive_AnalyticsProviderAdjust ต้องเพิ่มลงใน main app target (Unity-iPhone) ด้วย

  4. ใน Build Settings ของ main app target ให้เพิ่มค่าสองค่าต่อไปนี้ใน Other Linker Flags (OTHER_LDFLAGS) ตามลำดับ

    • -Xlinker
    • -all_load