# Uncomment the next line to define a global platform for your project
source 'https://gitee.com/mirrors/CocoaPods-Specs.git'
platform :ios, '16.0'
use_frameworks!

# AdHoc is a custom configuration. Without this mapping CocoaPods only
# generates Debug/Release xcfilelists, and AdHoc builds fail to embed pods.
project 'QuickLocation.xcodeproj', {
  'Debug' => :debug,
  'Release' => :release,
  'AdHoc' => :release,
}

target 'QuickLocation' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for QuickLocation
  # Pods for Base
  pod 'Moya'
  pod 'ObjectMapper'
  pod 'RxCocoa'
  pod 'RxSwift'
  pod 'SwiftyUserDefaults'
  pod 'SwiftyJSON'
  pod 'URLNavigator'
  pod 'RxDataSources'
  pod 'RxSwiftExt'
  pod 'SwiftDate'
  pod 'RxGesture'
  pod 'CocoaLumberjack/Swift'
  pod 'KingfisherWebP'
  pod 'Masonry'

  
  #工具
  pod 'FLEX', :git => 'https://github.com/FLEXTool/FLEX.git', :configurations => ['Debug']
  pod 'HXPHPicker'
  pod 'SwiftKeychainWrapper'
  pod 'SGQRCode', '~> 4.1.0' #扫描
  #pod 'PGDatePicker'
  pod 'IQKeyboardManagerSwift'
  pod 'YBImageBrowser'
  pod 'YBImageBrowser/Video'  #视频功能
  pod 'YYImage' #, :git => 'https://github.com/QiuYeHong90/YYImage.git'
  pod 'YYImage/WebP'
  
  
  #UI
  pod 'SnapKit'
  pod 'MJRefresh'
  pod 'MBProgressHUD', :git => 'https://github.com/jdg/MBProgressHUD.git'
  pod 'MarqueeLabel'
  pod 'Popover'
  pod 'SDCycleScrollView'
  pod 'lottie-ios'
  pod 'TagListView', '~> 1.0'
  pod 'BRPickerView'
  
  #第三方SDk
  pod 'GYSDK' #个推一键登录
  pod 'OpenIMSDK' #OpenIM
  pod 'CocoaMQTT'  #MQTT

  #wechat
  pod 'WechatOpenSDK-XCFramework'
  
  #高德地图
  pod 'AMapNavi-NO-IDFA'     #导航SDK
  pod 'AMapLocation-NO-IDFA'  #定位SDK
  pod 'AMapSearch-NO-IDFA'  #搜索SDK

  #友盟
  pod 'UMCommon'    #必须集成
  pod 'UMDevice'    #必须集成
  pod 'UMAPM'
  
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'
    end
  end

  # These frameworks ship without a valid arm64-simulator slice (even some
  # xcframeworks contain device-only arm64). Linking them for simulator on
  # Xcode 15+ (arm64-only simulator) fails. Fix: remove EXCLUDED_ARCHS (so
  # simulator destinations appear), strip them from general OTHER_LDFLAGS,
  # and add them back only via OTHER_LDFLAGS[sdk=iphoneos*].
  device_only_fws = %w[AMapFoundationKit AMapLocationKit AMapNaviKit ZXSDK GeYanSdk GTCommonSDK]
  device_only_dirs = %w[AMapFoundation-NO-IDFA AMapLocation-NO-IDFA AMapNavi-NO-IDFA ZXSDK GYSDK GTCommonSDK]


  Dir.glob(File.join(installer.sandbox.root, 'Target Support Files', '**', '*.xcconfig')).each do |path|
    content = File.read(path)

    # Remove arm64 exclusion
    content.gsub!(/^EXCLUDED_ARCHS\[sdk=iphonesimulator\*\] = arm64.*\n?/, '')

    if content =~ /^OTHER_LDFLAGS = (.+)$/
      ldflags = $1
      stripped_ld = false

      device_only_fws.each do |fw|
        if ldflags.gsub!(/ *-(weak_)?framework "#{fw}"/, '')
          stripped_ld = true
        end
      end

      content.sub!(/^OTHER_LDFLAGS = .+$/, "OTHER_LDFLAGS = #{ldflags}")

      # Remove any old conditional lines
      content.gsub!(/^OTHER_LDFLAGS\[sdk=iphonesimulator\*\].*\n?/, '')
      content.gsub!(/^OTHER_LDFLAGS\[sdk=iphoneos\*\].*\n?/, '')

      # Only add device-only conditional if we actually stripped something
      if stripped_ld
        device_flags = device_only_fws.map { |fw| %(-framework "#{fw}") }.join(' ')
        content += "\nOTHER_LDFLAGS[sdk=iphoneos*] = $(inherited) #{device_flags}\n"
      end
    end

    # Strip device-only dirs from FRAMEWORK_SEARCH_PATHS and move to iphoneos only
    if content =~ /^FRAMEWORK_SEARCH_PATHS = (.+)$/
      fsp = $1
      device_search_paths = []

      device_only_dirs.each do |dir|
        %w[PODS_ROOT PODS_CONFIGURATION_BUILD_DIR PODS_XCFRAMEWORKS_BUILD_DIR].each do |var|
          pattern = / *"\$\{#{var}\}\/#{dir}"/
          if fsp.match?(pattern)
            fsp.gsub!(pattern, '')
            device_search_paths << "\"${#{var}}/#{dir}\""
          end
        end
      end

      content.sub!(/^FRAMEWORK_SEARCH_PATHS = .+$/, "FRAMEWORK_SEARCH_PATHS = #{fsp}")
      content.gsub!(/^FRAMEWORK_SEARCH_PATHS\[sdk=iphoneos\*\].*\n?/, '')

      unless device_search_paths.empty?
        content += "\nFRAMEWORK_SEARCH_PATHS[sdk=iphoneos*] = $(inherited) #{device_search_paths.uniq.join(' ')}\n"
      end
    end

    if File.basename(path) == 'Pods-QuickLocation.adhoc.xcconfig' && content !~ /SWIFT_ACTIVE_COMPILATION_CONDITIONS/
      content += "\nSWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) AdHoc\n"
    end

    File.write(path, content)
  end
end
