Class: Pindo::XcodeBuildConfig
- Inherits:
-
Object
- Object
- Pindo::XcodeBuildConfig
- Defined in:
- lib/pindo/module/xcode/xcode_build_config.rb
Class Method Summary collapse
-
.add_single_scheme(plist_dict, scheme_value) ⇒ Boolean
添加单个scheme到plist字典中.
-
.add_url_schemes(project_dir: nil, scheme_name: nil) ⇒ Boolean
添加URL Schemes到iOS工程的Info.plist.
-
.configure_xcode_project(project_dir:) ⇒ Boolean
配置 Xcode 项目(封装 configproj 的核心逻辑) 注意:调用此方法前必须先通过 IosConfigParser.instance.load_config 加载配置.
-
.download_and_replace_icon_from_url(project_dir: nil, icon_url: nil) ⇒ Boolean
从URL下载Icon并替换iOS工程的Icon.
-
.update_entitlements_config(project_dir: nil) ⇒ Boolean
更新entitlements配置 根据entitlements文件内容,同步更新config.json中的配置 如果entitlements中没有icloud或app group,则从config.json中移除对应配置 使用 IosConfigParser 单例类获取和更新配置.
-
.update_ios_project_version(project_dir: nil, version: nil, build_number: nil) ⇒ Boolean
更新iOS工程版本号.
-
.update_project_with_workflow(project_dir: nil, workflow_packname: nil, project_id: nil) ⇒ Boolean
使用package_name一次性更新Display Name、Bundle ID和URL Schemes(基于package_name) 优化版本:只读写一次plist文件,提高性能 注意:此函数只添加基于package_name的URL Scheme,基于实际Bundle ID的URL Scheme 将在update_url_schemes_with_bundleid函数中统一添加(在证书配置之后).
-
.update_url_schemes_with_bundleid(project_dir: nil, package_name: nil) ⇒ Boolean
根据当前项目中的实际 Bundle ID 重新更新 URL Schemes 此函数用于在证书配置后更新 URL Schemes,确保与最终的 Bundle ID 匹配.
Class Method Details
.add_single_scheme(plist_dict, scheme_value) ⇒ Boolean
添加单个scheme到plist字典中
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/pindo/module/xcode/xcode_build_config.rb', line 254 def self.add_single_scheme(plist_dict, scheme_value) return false if scheme_value.nil? || scheme_value.empty? # 检查是否已存在 return false if plist_dict["CFBundleURLTypes"].any? { |item| item["CFBundleURLName"] == scheme_value } # 创建新的URL Type url_type = { "CFBundleTypeRole" => "Editor", "CFBundleURLName" => scheme_value, "CFBundleURLSchemes" => [scheme_value] } plist_dict["CFBundleURLTypes"] << url_type return true end |
.add_url_schemes(project_dir: nil, scheme_name: nil) ⇒ Boolean
添加URL Schemes到iOS工程的Info.plist
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/pindo/module/xcode/xcode_build_config.rb', line 198 def self.add_url_schemes(project_dir: nil, scheme_name: nil) raise ArgumentError, "项目目录不能为空" if project_dir.nil? project_fullname = Dir.glob(File.join(project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)} return false if project_fullname.nil? info_plist_path = nil bundleid_scheme_name = nil project_obj = Xcodeproj::Project.open(project_fullname) project_obj.targets.each do |target| if target.product_type.to_s.eql?("com.apple.product-type.application") temp_info_file = target.build_configurations.first.build_settings['INFOPLIST_FILE'] if temp_info_file && !temp_info_file.empty? info_plist_path = File.join(project_dir, temp_info_file) end bundleid_scheme_name = target.build_configurations.first.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] break # 找到第一个application target即可 end end return false unless info_plist_path && File.exist?(info_plist_path) info_plist_dict = Xcodeproj::Plist.read_from_path(info_plist_path) info_plist_dict["CFBundleURLTypes"] ||= [] schemes_added = [] # 添加基于项目名的scheme if scheme_name && !scheme_name.empty? scheme_value = scheme_name.to_s.gsub(/[^a-zA-Z0-9]/, '').downcase if add_single_scheme(info_plist_dict, scheme_value) schemes_added << scheme_value end end # 添加基于Bundle ID的scheme(从PRODUCT_BUNDLE_IDENTIFIER中读取) if bundleid_scheme_name && !bundleid_scheme_name.empty? bundleid_scheme_value = bundleid_scheme_name.gsub(/[^a-zA-Z0-9]/, '').downcase if add_single_scheme(info_plist_dict, bundleid_scheme_value) schemes_added << bundleid_scheme_value end end # 保存修改 if schemes_added.any? Xcodeproj::Plist.write_to_path(info_plist_dict, info_plist_path) schemes_added.each { |s| puts " ✓ 已添加URL Scheme: #{s}" } end return true end |
.configure_xcode_project(project_dir:) ⇒ Boolean
配置 Xcode 项目(封装 configproj 的核心逻辑)注意:调用此方法前必须先通过 IosConfigParser.instance.load_config 加载配置
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
# File 'lib/pindo/module/xcode/xcode_build_config.rb', line 498 def self.configure_xcode_project(project_dir:) require 'pindo/config/ios_config_parser' require 'pindo/module/xcode/xcode_build_helper' require 'pindo/module/xcode/xcode_res_helper' require 'pindo/module/xcode/xcode_app_config' require 'pindo/module/build/swark_helper' require 'pindo/base/git_handler' # 使用已加载的 IosConfigParser 单例 config_parser = Pindo::IosConfigParser.instance config_json = config_parser.config_json bundle_id = config_parser.bundle_id # 验证配置已加载 if config_json.nil? || config_json.empty? raise Informative, "配置未加载,请先调用 IosConfigParser.instance.load_config" end if bundle_id.nil? || bundle_id.empty? raise Informative, "无法从配置中获取 Bundle ID" end # 获取项目名称 project_fullname = Dir.glob(File.join(project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)} if project_fullname.nil? || !File.exist?(project_fullname) raise Informative, "找不到 .xcodeproj 文件,请检查项目目录" end proj_name = File.basename(project_fullname, ".xcodeproj") # 1. 安装 Google Plist Funlog.instance.("正在替换 google-info.plist...") google_info_config_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: bundle_id) Pindo::XcodeBuildHelper.install_google_plist( project_dir: project_dir, app_config_dir: google_info_config_dir ) Funlog.instance.("替换 google-info.plist 完成!") # 2. 创建和替换 Icon app_config_dir = google_info_config_dir icon_name = File.join(app_config_dir, "fastlane", "icon.png") if File.exist?(icon_name) time = Time.now.strftime('%m%d-%H%M%S') new_icon_dir = File.join(project_dir, "icon_#{time}") Funlog.instance.("正在创建 icon...") Pindo::XcodeResHelper.create_icons(icon_name: icon_name, new_icon_dir: new_icon_dir) Funlog.instance.("创建 icon 完成!") Funlog.instance.("正在替换 icon...") Pindo::XcodeResHelper.install_icon(proj_dir: project_dir, new_icon_dir: new_icon_dir) Funlog.instance.("替换 icon 完成!") begin FileUtils.rm_rf(new_icon_dir) rescue StandardError => err # 忽略清理错误 end else Funlog.instance.("未找到 icon 文件: #{icon_name}") end # 3. 替换启动页 Funlog.instance.("正在替换启动页...") launchimg_pub_path = File.join(app_config_dir, "launch") if Dir.exist?(launchimg_pub_path) Pindo::XcodeResHelper.install_launchimg( proj_dir: project_dir, launchimg_pub_path: launchimg_pub_path ) Funlog.instance.("启动页处理完成!") else Funlog.instance.("未找到启动页目录: #{launchimg_pub_path}") end # 4. 添加项目模块 # 需要 include XcodeAppConfig 模块的方法,这里创建一个临时对象 config_helper = Object.new config_helper.extend(Pindo::XcodeAppConfig) config_helper.add_project_modue( project_dir: project_dir, proj_name: proj_name, config_json: config_json ) # 5. 修改 Info.plist Funlog.instance.("正在修改工程配置...") Pindo::XcodeBuildHelper.modify_info_plist( project_dir: project_dir, proj_name: proj_name, config_json: config_json ) # 6. 修改项目配置 Pindo::XcodeBuildHelper.modify_project_config( project_dir: project_dir, proj_name: proj_name, config_json: config_json ) # 7. 修改 AppPrefix.plist appprefix_file = "AppPrefix.plist" if config_json['project_info'] && config_json['project_info']['appprefix_plist'] appprefix_file = config_json['project_info']['appprefix_plist'] end config_helper.modify_appprefix_plist( project_dir: project_dir, appprefix_file: appprefix_file, config_json: config_json ) Funlog.instance.("工程配置修改完成!") # 8. 检查 Swark 授权 deploy_identifier = config_json['app_info']['app_identifier'] || bundle_id Pindo::SwarkHelper.( config_json: config_json, buid_type: 'dev', deploy_identifier: deploy_identifier ) return true rescue StandardError => e Funlog.instance.("配置 Xcode 项目失败: #{e.}") puts e.backtrace return false end |
.download_and_replace_icon_from_url(project_dir: nil, icon_url: nil) ⇒ Boolean
从URL下载Icon并替换iOS工程的Icon
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/pindo/module/xcode/xcode_build_config.rb', line 429 def self.download_and_replace_icon_from_url(project_dir: nil, icon_url: nil) # 参数校验 - 不抛出异常,返回 false if project_dir.nil? Funlog.instance.("Icon 替换失败: 项目目录不能为空") return false end if icon_url.nil? || icon_url.empty? Funlog.instance.("Icon 替换失败: Icon URL不能为空") return false end puts "\n检测到项目 Icon URL: #{icon_url}" # 创建临时目录(所有 icon 处理都在此目录内完成) temp_icon_dir = File.join(project_dir, ".pindo_temp_ios_icon") icon_download_path = nil replace_success = false begin # 先清理旧的临时目录,确保干净的环境 FileUtils.rm_rf(temp_icon_dir) if File.exist?(temp_icon_dir) FileUtils.mkdir_p(temp_icon_dir) icon_download_path = File.join(temp_icon_dir, "ios_downloaded_icon.png") # 使用带重试机制的下载 unless IconDownloader.download_icon_with_retry(icon_url: icon_url, save_path: icon_download_path, max_retries: 3) Funlog.instance.("Icon 下载失败: 已重试3次") return false end # 生成新的 icon 目录(放在临时目录内部),先清理确保干净环境 new_icon_dir = File.join(temp_icon_dir, "ios_generated_icons") FileUtils.rm_rf(new_icon_dir) if File.exist?(new_icon_dir) FileUtils.mkdir_p(new_icon_dir) # 创建各种尺寸的 icon Funlog.instance.("正在创建 icon...") XcodeResHelper.create_icons( icon_name: icon_download_path, new_icon_dir: new_icon_dir ) Funlog.instance.("创建 icon 完成!") # 替换工程中的 icon Funlog.instance.("正在替换 icon...") XcodeResHelper.install_icon( proj_dir: project_dir, new_icon_dir: new_icon_dir ) Funlog.instance.("替换 icon 完成!") replace_success = true rescue => e Funlog.instance.("Icon 处理失败: #{e.}") puts e.backtrace replace_success = false ensure # 清理临时文件(无论成功失败都清理) FileUtils.rm_rf(temp_icon_dir) if temp_icon_dir && File.exist?(temp_icon_dir) end return replace_success end |
.update_entitlements_config(project_dir: nil) ⇒ Boolean
更新entitlements配置根据entitlements文件内容,同步更新config.json中的配置如果entitlements中没有icloud或app group,则从config.json中移除对应配置使用 IosConfigParser 单例类获取和更新配置
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/pindo/module/xcode/xcode_build_config.rb', line 370 def self.update_entitlements_config(project_dir: nil) raise ArgumentError, "项目目录不能为空" if project_dir.nil? # 使用 IosConfigParser 单例获取配置 config_parser = Pindo::IosConfigParser.instance config_json = config_parser.config_json config_file_path = config_parser.config_file_path return false if config_json.nil? || config_file_path.nil? project_fullname = Dir.glob(File.join(project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)} return false if project_fullname.nil? entitlements_plist_path = nil project_obj = Xcodeproj::Project.open(project_fullname) project_obj.targets.each do |target| if target.product_type.to_s.eql?("com.apple.product-type.application") temp_entitlements_file = target.build_configurations.first.build_settings['CODE_SIGN_ENTITLEMENTS'] if temp_entitlements_file && !temp_entitlements_file.empty? entitlements_plist_path = File.join(project_dir, temp_entitlements_file) end break # 找到第一个application target即可 end end # 处理entitlements配置 if entitlements_plist_path && File.exist?(entitlements_plist_path) entitlements_plist_dict = Xcodeproj::Plist.read_from_path(entitlements_plist_path) # 如果entitlements中没有icloud配置,从config.json中移除 if entitlements_plist_dict["com.apple.developer.icloud-container-identifiers"].nil? if config_json["app_info"] && config_json["app_info"]['app_icloud_id'] config_json["app_info"].delete('app_icloud_id') end end # 如果entitlements中没有app group配置,从config.json中移除 if entitlements_plist_dict["com.apple.security.application-groups"].nil? if config_json["app_info"] && config_json["app_info"]['app_group_id'] config_json["app_info"].delete('app_group_id') end end # 保存更新后的config.json File.open(config_file_path, "w") do |f| f.write(JSON.pretty_generate(config_json)) end return true end return false end |
.update_ios_project_version(project_dir: nil, version: nil, build_number: nil) ⇒ Boolean
更新iOS工程版本号
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/pindo/module/xcode/xcode_build_config.rb', line 276 def self.update_ios_project_version(project_dir: nil, version: nil, build_number: nil) raise ArgumentError, "项目目录不能为空" if project_dir.nil? raise ArgumentError, "版本号不能为空" if version.nil? raise ArgumentError, "Build号不能为空" if build_number.nil? Funlog.instance.("正在更新iOS工程版本信息...") begin # 查找.xcodeproj文件 xcodeproj_path = find_xcodeproj(project_dir) if xcodeproj_path.nil? Funlog.instance.("未找到Xcode项目文件") return false end # 打开Xcode项目 project = Xcodeproj::Project.open(xcodeproj_path) # 更新所有application类型target的版本号 updated_targets = [] project.targets.each do |target| # 只处理application类型的target if target.product_type.to_s.eql?("com.apple.product-type.application") target.build_configurations.each do |config| # 更新版本号 config.build_settings['MARKETING_VERSION'] = version config.build_settings['CURRENT_PROJECT_VERSION'] = build_number.to_s # 兼容旧的设置方式,通过Info.plist更新 if config.build_settings['INFOPLIST_FILE'] info_plist_path = File.join(project_dir, config.build_settings['INFOPLIST_FILE']) if File.exist?(info_plist_path) update_info_plist(info_plist_path, version, build_number.to_s) end end end updated_targets << target.name end end # 保存项目 project.save if updated_targets.empty? Funlog.instance.("未找到需要更新的application target") return false else Funlog.instance.("iOS版本更新完成!") puts " ✓ 版本号已更新: #{version}" puts " ✓ Build号已更新: #{build_number}" puts " ✓ 更新的Target: #{updated_targets.join(', ')}" return true end rescue StandardError => e Funlog.instance.("更新iOS版本失败: #{e.}") return false end end |
.update_project_with_workflow(project_dir: nil, workflow_packname: nil, project_id: nil) ⇒ Boolean
使用package_name一次性更新Display Name、Bundle ID和URL Schemes(基于package_name)优化版本:只读写一次plist文件,提高性能注意:此函数只添加基于package_name的URL Scheme,基于实际Bundle ID的URL Scheme
将在update_url_schemes_with_bundleid函数中统一添加(在证书配置之后)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/pindo/module/xcode/xcode_build_config.rb', line 21 def self.update_project_with_workflow(project_dir: nil, workflow_packname: nil, project_id: nil) raise ArgumentError, "项目目录不能为空" if project_dir.nil? raise ArgumentError, "Workflow Package Name不能为空" if workflow_packname.nil? # 生成各种值 display_name = workflow_packname.gsub(/[^a-zA-Z0-9\s]/, '').gsub(/\s+/, '') bundle_id_suffix = workflow_packname.gsub(/[^a-zA-Z0-9]/, '').downcase final_bundle_id = "com.heroneverdie101.#{bundle_id_suffix}" package_scheme = workflow_packname.gsub(/[^a-zA-Z0-9]/, '').downcase project_fullname = Dir.glob(File.join(project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)} return false if project_fullname.nil? info_plist_path = nil app_target = nil project_obj = Xcodeproj::Project.open(project_fullname) project_obj.targets.each do |target| if target.product_type.to_s.eql?("com.apple.product-type.application") temp_info_file = target.build_configurations.first.build_settings['INFOPLIST_FILE'] if temp_info_file && !temp_info_file.empty? info_plist_path = File.join(project_dir, temp_info_file) end app_target = target break # 找到第一个application target即可 end end return false unless info_plist_path && File.exist?(info_plist_path) # 一次性读取plist info_plist_dict = Xcodeproj::Plist.read_from_path(info_plist_path) # 1. 更新Info Plist Display Name info_plist_dict["CFBundleDisplayName"] = display_name # 2. 更新 Bundle ID(plist) info_plist_dict["CFBundleIdentifier"] = final_bundle_id # 3. 添加 URL Schemes info_plist_dict["CFBundleURLTypes"] ||= [] # 添加基于 package_name 的 URL Scheme # 注意:基于 Bundle ID 的 URL Scheme 将在 update_url_schemes_with_bundleid 函数中统一添加 if add_single_scheme(info_plist_dict, package_scheme) puts " ✓ 已添加URL Scheme: #{package_scheme} (基于 Package Name)" end # 4. 添加 JPS 快捷操作(UIApplicationShortcutItems) if project_id && !project_id.to_s.empty? # 创建或获取 UIApplicationShortcutItems 数组 info_plist_dict["UIApplicationShortcutItems"] ||= [] # 构建快捷操作类型 shortcut_type = "jps_project?#{project_id}" jps_title = "访问 JPS 详情" # 先查找是否存在标题为"访问 JPS 详情"的快捷操作(无论其 type 是什么) existing_shortcut = info_plist_dict["UIApplicationShortcutItems"].find do |item| item["UIApplicationShortcutItemTitle"] == jps_title end if existing_shortcut # 如果存在,检查 type 是否一致 if existing_shortcut["UIApplicationShortcutItemType"] == shortcut_type puts " ✓ JPS 快捷操作已存在: #{shortcut_type}" else # type 不一致,更新为新的 type old_type = existing_shortcut["UIApplicationShortcutItemType"] existing_shortcut["UIApplicationShortcutItemType"] = shortcut_type existing_shortcut["UIApplicationShortcutItemIconType"] = "UIApplicationShortcutIconTypeBookmark" puts " ✓ 已更新 JPS 快捷操作: #{old_type} -> #{shortcut_type}" end else # 不存在,添加新的快捷操作 jps_shortcut = { "UIApplicationShortcutItemType" => shortcut_type, "UIApplicationShortcutItemTitle" => jps_title, "UIApplicationShortcutItemIconType" => "UIApplicationShortcutIconTypeBookmark" } info_plist_dict["UIApplicationShortcutItems"] << jps_shortcut puts " ✓ 已添加 JPS 快捷操作: #{shortcut_type}" end end # 一次性写入plist Xcodeproj::Plist.write_to_path(info_plist_dict, info_plist_path) # 5. 更新 Xcode 项目中的 PRODUCT_BUNDLE_IDENTIFIER if app_target app_target.build_configurations.each do |config| config.build_settings['INFOPLIST_KEY_CFBundleDisplayName'] = display_name config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = final_bundle_id end project_obj.save end puts " ✓ Display Name 已更新为: #{display_name}" puts " ✓ Bundle ID 已更新为: #{final_bundle_id}" return true end |
.update_url_schemes_with_bundleid(project_dir: nil, package_name: nil) ⇒ Boolean
根据当前项目中的实际 Bundle ID 重新更新 URL Schemes 此函数用于在证书配置后更新 URL Schemes,确保与最终的 Bundle ID 匹配
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/pindo/module/xcode/xcode_build_config.rb', line 129 def self.update_url_schemes_with_bundleid(project_dir: nil, package_name: nil) raise ArgumentError, "项目目录不能为空" if project_dir.nil? project_fullname = Dir.glob(File.join(project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)} return false if project_fullname.nil? info_plist_path = nil current_bundle_id = nil project_obj = Xcodeproj::Project.open(project_fullname) project_obj.targets.each do |target| if target.product_type.to_s.eql?("com.apple.product-type.application") temp_info_file = target.build_configurations.first.build_settings['INFOPLIST_FILE'] if temp_info_file && !temp_info_file.empty? info_plist_path = File.join(project_dir, temp_info_file) end # 获取当前实际的 Bundle ID current_bundle_id = target.build_configurations.first.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] break # 找到第一个application target即可 end end return false unless info_plist_path && File.exist?(info_plist_path) return false unless current_bundle_id && !current_bundle_id.empty? puts "\n根据更新后的 Bundle ID 重新配置 URL Schemes:" puts " 当前 Bundle ID: #{current_bundle_id}" # 读取 plist info_plist_dict = Xcodeproj::Plist.read_from_path(info_plist_path) info_plist_dict["CFBundleURLTypes"] ||= [] # 生成 schemes package_scheme = package_name ? package_name.gsub(/[^a-zA-Z0-9]/, '').downcase : nil bundle_scheme = current_bundle_id.gsub(/[^a-zA-Z0-9]/, '').downcase schemes_updated = [] # 添加基于 package_name 的 URL Scheme(如果提供了 package_name) if package_scheme && !package_scheme.empty? if add_single_scheme(info_plist_dict, package_scheme) schemes_updated << package_scheme puts " ✓ 已更新 URL Scheme: #{package_scheme} (基于 Package Name)" else puts " ✓ URL Scheme 已存在: #{package_scheme} (基于 Package Name)" end end # 添加基于实际 Bundle ID 的 URL Scheme if add_single_scheme(info_plist_dict, bundle_scheme) schemes_updated << bundle_scheme puts " ✓ 已更新 URL Scheme: #{bundle_scheme} (基于更新后的 Bundle ID)" else puts " ✓ URL Scheme 已存在: #{bundle_scheme} (基于更新后的 Bundle ID)" end # 写入 plist if schemes_updated.any? Xcodeproj::Plist.write_to_path(info_plist_dict, info_plist_path) puts " ✓ URL Schemes 更新完成" end return true end |