require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.0'

target 'JuicePlus' do
  config = use_native_modules!
  pod 'react-native-google-maps', :path => '../node_modules/react-native-maps'
  #pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency" #访问设备的广告标识符
  #pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral" #访问蓝牙
  #pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars" #访问日历
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"  #访问相机
  #pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"  #访问联系人
  #pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID"  #访问FaceID
  pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy" #访问高明度定位
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways" #始终访问位置信息
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse" #在使用中访问位置信息
  #pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary" #使用媒体库
  pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"  #使用麦克风
  #pod 'Permission-Motion', :path => "#{permissions_path}/Motion"  #运动权限
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications" #使用通知
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary" #使用照片库
  pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly" #添加照片
  #pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders"
  #pod 'Permission-Siri', :path => "#{permissions_path}/Siri"
  #pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition"
  #pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit"
  #谷歌通知启用
  pod 'Firebase/Core', :modular_headers => true
  pod 'Firebase/Analytics', :modular_headers => true
  pod 'Firebase/Messaging', :modular_headers => true
  pod 'FirebaseCoreInternal', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  #微软热更新
  pod 'CodePush', :path => '../node_modules/react-native-code-push'

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
  )

  target 'JuicePlusTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  #use_flipper!()
  #use_flipper!('Flipper' => '0.75.1', 'Flipper-Folly' => '2.5.3', 'Flipper-RSocket' => '1.3.1')

  #post_install do |installer|
  #  react_native_post_install(installer)
  #end

  #⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄修复iOS 14.5新建RN0.64无法运行⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄
  def find_and_replace(dir, findstr, replacestr)
    Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
        puts "Fix: " + name
        File.open(name, "w") { |file| file.puts replace }
        STDOUT.flush
      end
    end
    Dir[dir + '*/'].each(&method(:find_and_replace))
  end

  post_install do |installer|
    flipper_post_install(installer)
    find_and_replace("Pods/Flipper-Folly/folly/synchronization/DistributedMutex-inl.h",
    "atomic_notify_one(state)", "folly::atomic_notify_one(state)")

    find_and_replace("Pods/Flipper-Folly/folly/synchronization/DistributedMutex-inl.h",
    "atomic_wait_until(&state, previous | data, deadline)", "folly::atomic_wait_until(&state, previous | data, deadline)")
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' #将所有插件更新为iOS12可用
      end
    end
  end
  #⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃修复iOS 14.5新建RN0.64无法运行⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃
end
