Skip to content

Instantly share code, notes, and snippets.

@rumaniel
Created May 4, 2019 08:30
Show Gist options
  • Save rumaniel/b72e2d7f52e108d3957982ede24b00f0 to your computer and use it in GitHub Desktop.
Save rumaniel/b72e2d7f52e108d3957982ede24b00f0 to your computer and use it in GitHub Desktop.
fastlane action for update appicon
# Inspired by https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/update_app_identifier.rb
# coding: utf-8
module Fastlane
module Actions
class UpdateAppiconAndLaunchimageAction < Action
def self.run(params)
require 'plist'
require 'xcodeproj'
info_plist_key = 'INFOPLIST_FILE'
appicon_name = 'ASSETCATALOG_COMPILER_APPICON_NAME'
# Load .xcodeproj
project_path = params[:xcodeproj]
project = Xcodeproj::Project.open(project_path)
# Fetch the build configuration objects
configs = project.objects.select { |obj| obj.isa == 'XCBuildConfiguration'}
UI.user_error!("Not found XCBuildConfiguration from xcodeproj") unless configs.count > 0
configs = configs.select { |obj| obj.build_settings[info_plist_key] == params[:plist_path] }
UI.user_error!("Xcodeproj doesn't have configuration with info plist #{params[:plist_path]}.") unless configs.count > 0
# For each of the build configurations, set app identifier
configs.each do |c|
c.build_settings[appicon_name] = params[:appicon_name]
end
# Write changes to the file
project.save
UI.success("Updated #{params[:xcodeproj]} 💾.")
end
#####################################################
# @!group Documentation
#####################################################
def self.is_supported?(platform)
[:ios].include?(platform)
end
def self.description
"Update the project's bundle identifier"
end
def self.details
"Update an app identifier by either setting `ASSETCATALOG_COMPILER_APPICON_NAME`."
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :xcodeproj,
env_name: "FL_UPDATE_APPICON_PROJECT_PATH",
description: "Path to your Xcode project",
default_value: Dir['*.xcodeproj'].first,
verify_block: proc do |value|
UI.user_error!("Please pass the path to the project, not the workspace") unless value.end_with?(".xcodeproj")
UI.user_error!("Could not find Xcode project") unless File.exist?(value)
end),
FastlaneCore::ConfigItem.new(key: :plist_path,
env_name: "FL_UPDATE_APPICON_PLIST_PATH",
description: "Path to info plist, relative to your Xcode project",
verify_block: proc do |value|
UI.user_error!("Invalid plist file") unless value[-6..-1].casecmp(".plist").zero?
end),
FastlaneCore::ConfigItem.new(key: :appicon_name,
env_name: 'FL_APPICON_ID',
description: 'appicon name')
]
end
def self.authors
['ruman']
end
def self.category
:project
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment