Class: IOSWizard

Inherits:
Object show all
Includes:
Metadata
Defined in:
dragon/ios_wizard.rb

Instance Method Summary collapse

Methods included from Metadata

#get_metadata, #metadata_file_path, #write_blank_metadata

Constructor Details

#initializeIOSWizard

Returns a new instance of IOSWizard.


17
18
19
# File 'dragon/ios_wizard.rb', line 17

def initialize
  @doctor_executed_at = 0
end

Instance Method Details

#always_failObject


136
137
138
139
# File 'dragon/ios_wizard.rb', line 136

def always_fail
  return false if $gtk.ivar :rcb_release_mode
  return true
end

#app_id_from_provisioning_profile(environment) ⇒ Object


278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'dragon/ios_wizard.rb', line 278

def app_id_from_provisioning_profile environment
  application_identifier_index = (provisioning_profile_xml environment)[:children][0][:children][0][:children][13][:children][0][:children][0][:data]
  (provisioning_profile_xml environment)[:children][0][:children][0][:children][13][:children].each.with_index do |node, i|
    if node[:children] && node[:children][0] && node[:children][0][:data] == "application-identifier"
      application_identifier_index = i
      break
    end
  end

  app_id_with_team_identifier = (provisioning_profile_xml environment)[:children].first[:children].first[:children][13][:children][application_identifier_index + 1][:children].first[:data]
  team_identifier = team_identifier_from_provisioning_profile environment
  app_id_with_team_identifier.gsub "#{team_identifier}.", ""
end

#app_pathObject


929
930
931
# File 'dragon/ios_wizard.rb', line 929

def app_path
  "#{tmp_directory}/#{@app_name}.app"
end

#blow_away_tempObject


326
327
328
# File 'dragon/ios_wizard.rb', line 326

def blow_away_temp
  sh "rm -rf #{tmp_directory}"
end

#check_for_brewObject


155
156
157
158
159
160
161
162
163
164
165
166
# File 'dragon/ios_wizard.rb', line 155

def check_for_brew
  if !cli_app_exist?('brew')
    raise WizardException.new(
      "* You need to install Brew.",
      { w: 700, h: 388, path: get_reserved_sprite("brew.png") },
      "** 1. Go to http://brew.sh.",
      "** 2. Copy the command that starts with `/bin/bash -c` on the site.",
      "** 3. Open Terminal and run the command you copied from the website.",
      { w: 700, h: 99, path: get_reserved_sprite("terminal.png") },
    )
  end
end

#check_for_certsObject


363
364
365
366
367
368
369
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
# File 'dragon/ios_wizard.rb', line 363

def check_for_certs
  log_info "Attempting to find certificates on your computer."

  if !cli_app_exist?(security_cli_app)
    raise WizardException.new(
            "* It doesn't look like you have #{security_cli_app}.",
            "** 1. Open Disk Utility and run First Aid.",
            { w: 700, h: 148, path: get_reserved_sprite("disk-utility.png") },
          )
  end

  if valid_certs.length == 0
    raise WizardException.new(
            "* It doesn't look like you have any valid certs installed.",
            "** 1. Open Xcode.",
            "** 2. Log into your developer account. Xcode -> Preferences -> Accounts.",
            { w: 700, h: 98, path: get_reserved_sprite("login-xcode.png") },
            "** 3. After logging in, select Manage Certificates...",
            { w: 700, h: 115, path: get_reserved_sprite("manage-certificates.png") },
            "** 4. Add a certificate for Apple Development.",
            { w: 700, h: 217, path: get_reserved_sprite("add-cert.png") },
    )
    raise "You do not have any Apple development certs on this computer."
  end

  if @production_build
    @certificate_name = valid_certs.find_all { |f| f[:name].include? "Distribution" }.first[:name]
  else
    @certificate_name = valid_certs.find_all { |f| f[:name].include? "Development" }.first[:name]
  end
  log_info "I will be using Certificate: '#{@certificate_name}'."
end

#check_for_dev_profileObject


212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'dragon/ios_wizard.rb', line 212

def check_for_dev_profile
  @provisioning_profile_path = "profiles/development.mobileprovision"
  if !($gtk.read_file @provisioning_profile_path)
    $gtk.system "mkdir -p #{relative_path}/profiles"
    $gtk.system "open #{relative_path}/profiles"
    $gtk.system "echo Download the mobile provisioning profile and place it here with the name development.mobileprovision > #{relative_path}/profiles/README.txt"
    raise WizardException.new(
      "* I didn't find a mobile provision.",
      "** 1. Go to http://developer.apple.com and click \"Certificates, IDs & Profiles\".",
      "** 2. Add an App Identifier.",
      "** 3. Select the App IDs option from the list.",
      { w: 700, h: 75, path: get_reserved_sprite("identifiers.png") },
      "** 4. Add your Device next. You can use idevice_id -l to get the UUID of your device.",
      { w: 365, h: 69, path: get_reserved_sprite("device-link.png") },
      "** 5. Create a Profile. Associate your certs, id, and device.",
      { w: 300, h: 122, path: get_reserved_sprite("profiles.png") },
      "** 6. Download the mobile provision and save it to 'profiles/development.mobileprovision'.",
      { w: 200, h: 124, path: get_reserved_sprite("profiles-folder.png") },
    )
  end
end

#check_for_deviceObject


342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'dragon/ios_wizard.rb', line 342

def check_for_device
  log_info "Looking for device."

  if !cli_app_exist?(idevice_id_cli_app)
    raise WizardException.new(
       "* It doesn't look like you have the libimobiledevice iOS protocol library installed.",
       "** 1. Open Terminal.",
       { w: 700, h: 99, path: get_reserved_sprite("terminal.png") },
       "** 2. Run: `brew install libimobiledevice`.",
       { w: 500, h: 93, path: get_reserved_sprite("brew-install-libimobiledevice.png") },
    )
  end

  if connected_devices.length == 0
    raise WizardException.new("* I couldn't find any connected devices. Connect your iOS device to your Mac and try again.")
  end

  @device_id = connected_devices.first
  log_info "I will be using device with UUID #{@device_id}"
end

#check_for_distribution_profileObject


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'dragon/ios_wizard.rb', line 190

def check_for_distribution_profile
  @provisioning_profile_path = "profiles/distribution.mobileprovision"
  if !($gtk.read_file @provisioning_profile_path)
    $gtk.system "mkdir -p #{relative_path}/profiles"
    $gtk.system "open #{relative_path}/profiles"
    $gtk.system "echo Download the mobile provisioning profile and place it here with the name distribution.mobileprovision > #{relative_path}/profiles/README.txt"
    raise WizardException.new(
      "* I didn't find a mobile provision.",
      "** 1. Go to http://developer.apple.com and click \"Certificates, IDs & Profiles\".",
      "** 2. Add an App Identifier.",
      "** 3. Select the App IDs option from the list.",
      { w: 700, h: 75, path: get_reserved_sprite("identifiers.png") },
      "** 4. Add your Device next. You can use idevice_id -l to get the UUID of your device.",
      { w: 365, h: 69, path: get_reserved_sprite("device-link.png") },
      "** 5. Create a Profile. Associate your certs, id, and device.",
      { w: 300, h: 122, path: get_reserved_sprite("profiles.png") },
      "** 6. Download the mobile provision and save it to 'profiles/development.mobileprovision'.",
      { w: 200, h: 124, path: get_reserved_sprite("profiles-folder.png") },
    )
  end
end

#check_for_xcodeObject


141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'dragon/ios_wizard.rb', line 141

def check_for_xcode
  if !cli_app_exist?(xcodebuild_cli_app)
    raise WizardException.new(
      "* You need Xcode to use $wizards.ios.start.",
      { w: 75, h: 75, path: get_reserved_sprite("xcode.png") },
      "** 1. Go to http://developer.apple.com and register.",
      "** 2. Download Xcode 11.3+ from http://developer.apple.com/downloads.",
      "   NOTE: DO NOT install Xcode from the App Store. Use the link above.",
      { w: 700, h: 359, path: get_reserved_sprite("xcode-downloads.png") },
      "** 3. After installing. Open up Xcode to accept the EULA."
    )
  end
end

#cli_app_exist?(app) ⇒ Boolean

Returns:

  • (Boolean)

432
433
434
# File 'dragon/ios_wizard.rb', line 432

def cli_app_exist? app
  `which #{app}`.strip.length != 0
end

#code_sign_payloadObject


475
476
477
478
479
480
481
482
# File 'dragon/ios_wizard.rb', line 475

def code_sign_payload
  log_info "Signing app with #{@certificate_name}."

  sh "CODESIGN_ALLOCATE=\"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate\" /usr/bin/codesign -f -s \"#{@certificate_name}\" --entitlements #{tmp_directory}/Entitlements.plist \"#{tmp_directory}/ipa_root/Payload/#{@app_name}.app\""
  sh "CODESIGN_ALLOCATE=\"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate\" /usr/bin/codesign -f -s \"#{@certificate_name}\" --entitlements #{tmp_directory}/Entitlements.plist \"#{tmp_directory}/ipa_root/Payload/#{@app_name}.app/Runtime\""

  @code_sign_completed = true
end

#compile_iconsObject


997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
# File 'dragon/ios_wizard.rb', line 997

def compile_icons
  cmd = <<-S
"/Applications/Xcode.app/Contents/Developer/usr/bin/actool" --output-format human-readable-text \
                                                          --notices --warnings --platform iphoneos \
                                                          --minimum-deployment-target 10.3 \
                                                          --target-device iphone \
                                                          --target-device ipad  --app-icon 'AppIcon' \
                                                          --output-partial-info-plist '#{app_path}/AssetCatalog-Info.plist' \
                                                          --compress-pngs --compile "#{app_path}" \
                                                          "#{app_path}/Assets.xcassets"
S
  sh cmd
end

#connected_devicesObject


426
427
428
429
430
# File 'dragon/ios_wizard.rb', line 426

def connected_devices
  sh("idevice_id -l").strip.each_line.map do |l|
    l.strip
  end.reject { |l| l.length == 0 }
end

#create_ipaObject


961
962
963
964
# File 'dragon/ios_wizard.rb', line 961

def create_ipa
  do_zip
  sh "cp \"#{tmp_directory}/ipa_root/archive.zip\" \"#{tmp_directory}/#{@app_name}.ipa\""
end

#create_payload_directoryObject


941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
# File 'dragon/ios_wizard.rb', line 941

def create_payload_directory
  sh "cp #{@provisioning_profile_path} \"#{app_path}/embedded.mobileprovision\""
  sh "/usr/bin/plutil -convert binary1 \"#{app_path}/Info.plist\""
  write_ip_address
  sh "rm \"#{@app_name}\".ipa"
  sh "rm -rf \"#{app_path}/app\""
  sh "rm -rf \"#{app_path}/sounds\""
  sh "rm -rf \"#{app_path}/sprites\""
  sh "rm -rf \"#{app_path}/data\""
  sh "rm -rf \"#{app_path}/fonts\""
  sh "cp -r \"#{root_folder}/app/\" \"#{app_path}/app/\""
  sh "cp -r \"#{root_folder}/sounds/\" \"#{app_path}/sounds/\""
  sh "cp -r \"#{root_folder}/sprites/\" \"#{app_path}/sprites/\""
  sh "cp -r \"#{root_folder}/data/\" \"#{app_path}/data/\""
  sh "cp -r \"#{root_folder}/fonts/\" \"#{app_path}/fonts/\""
  sh "mkdir -p #{tmp_directory}/ipa_root/Payload"
  sh "cp -r \"#{app_path}\" \"#{tmp_directory}/ipa_root/Payload\""
  sh "chmod -R 755 \"#{tmp_directory}/ipa_root/Payload\""
end

#deployObject


985
986
987
988
# File 'dragon/ios_wizard.rb', line 985

def deploy
  sh "XCODE_DIR=\"/Applications/Xcode.app/Contents/Developer\" \"#{relative_path}/dragonruby-deploy-ios\" -d \"#{@device_id}\" \"#{tmp_directory}/#{@app_name}.ipa\""
  log_info "Check your device!!"
end

#determine_app_idObject


305
306
307
308
309
# File 'dragon/ios_wizard.rb', line 305

def determine_app_id
  @app_id = app_id_from_provisioning_profile @opts[:env]

  log_info "App Identifier is set to : #{@app_id}"
end

#determine_app_nameObject


244
245
246
247
# File 'dragon/ios_wizard.rb', line 244

def determine_app_name
  @app_name = (provisioning_profile_xml @opts[:env])[:children].first[:children].first[:children][1][:children].first[:data]
  log_info "App name is: #{@app_name}."
end

#determine_app_version(opts) ⇒ Object


249
250
251
252
253
254
255
256
# File 'dragon/ios_wizard.rb', line 249

def determine_app_version opts
  version = @opts[:version]
  unless version
    version = [:version]
    version = version.start_with?('#') ? '1.0' : version.split('=').last
  end
  version.to_s
end

#determine_team_identifierObject


239
240
241
242
# File 'dragon/ios_wizard.rb', line 239

def determine_team_identifier
  @team_name = (team_identifier_from_provisioning_profile @opts[:env])
  log_info "Team Identifier is: #{@team_name}"
end

#development_write_info_plistObject


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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
# File 'dragon/ios_wizard.rb', line 598

def development_write_info_plist
  log_info "Adding Info.plist."

  info_plist_string = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
      <key>NSAppTransportSecurity</key>
      <dict>
              <key>NSAllowsArbitraryLoads</key>
              <true/>
              <key>NSExceptionDomains</key>
              <dict>
                      <key>google.com</key>
                      <dict>
                              <key>NSExceptionAllowsInsecureHTTPLoads</key>
                              <true/>
                              <key>NSIncludesSubdomains</key>
                              <true/>
                      </dict>
              </dict>
      </dict>
      <key>BuildMachineOSBuild</key>
      <string>20D91</string>
      <key>CFBundleDevelopmentRegion</key>
      <string>en</string>
      <key>CFBundleDisplayName</key>
      <string>:app_name</string>
      <key>CFBundleExecutable</key>
      <string>Runtime</string>
      <key>CFBundleIconFiles</key>
      <array>
              <string>AppIcon60x60</string>
      </array>
      <key>CFBundleIcons</key>
      <dict>
              <key>CFBundlePrimaryIcon</key>
              <dict>
                      <key>CFBundleIconFiles</key>
                      <array>
                              <string>AppIcon60x60</string>
                      </array>
                      <key>CFBundleIconName</key>
                      <string>AppIcon</string>
              </dict>
      </dict>
      <key>CFBundleIcons~ipad</key>
      <dict>
              <key>CFBundlePrimaryIcon</key>
              <dict>
                      <key>CFBundleIconFiles</key>
                      <array>
                              <string>AppIcon60x60</string>
                              <string>AppIcon76x76</string>
                              <string>AppIcon83.5x83.5</string>
                      </array>
                      <key>CFBundleIconName</key>
                      <string>AppIcon</string>
              </dict>
      </dict>
      <key>CFBundleIdentifier</key>
      <string>:app_id</string>
      <key>CFBundleInfoDictionaryVersion</key>
      <string>6.0</string>
      <key>CFBundleName</key>
      <string>:app_name</string>
      <key>CFBundlePackageType</key>
      <string>APPL</string>
      <key>CFBundleShortVersionString</key>
      <string>5.2</string>
      <key>CFBundleSignature</key>
      <string>????</string>
      <key>CFBundleSupportedPlatforms</key>
      <array>
              <string>iPhoneOS</string>
      </array>
      <key>CFBundleVersion</key>
      <string>5.2</string>
      <key>DTCompiler</key>
      <string>com.apple.compilers.llvm.clang.1_0</string>
      <key>DTPlatformBuild</key>
      <string>18D46</string>
      <key>DTPlatformName</key>
      <string>iphoneos</string>
      <key>DTPlatformVersion</key>
      <string>14.4</string>
      <key>DTSDKBuild</key>
      <string>18D46</string>
      <key>DTSDKName</key>
      <string>iphoneos14.4</string>
      <key>DTXcode</key>
      <string>0124</string>
      <key>DTXcodeBuild</key>
      <string>12D4e</string>
      <key>MinimumOSVersion</key>
      <string>14.4</string>
      <key>UIAppFonts</key>
      <array/>
      <key>UIBackgroundModes</key>
      <array/>
      <key>UIDeviceFamily</key>
      <array>
              <integer>1</integer>
              <integer>2</integer>
      </array>
      <key>UILaunchImages</key>
      <array>
              <dict>
                      <key>UILaunchImageMinimumOSVersion</key>
                      <string>7.0</string>
                      <key>UILaunchImageName</key>
                      <string>[email protected]</string>
                      <key>UILaunchImageOrientation</key>
                      <string>Portrait</string>
                      <key>UILaunchImageSize</key>
                      <string>{320, 568}</string>
              </dict>
              <dict>
                      <key>UILaunchImageMinimumOSVersion</key>
                      <string>7.0</string>
                      <key>UILaunchImageName</key>
                      <string>[email protected]</string>
                      <key>UILaunchImageOrientation</key>
                      <string>Portrait</string>
                      <key>UILaunchImageSize</key>
                      <string>{375, 667}</string>
              </dict>
              <dict>
                      <key>UILaunchImageMinimumOSVersion</key>
                      <string>7.0</string>
                      <key>UILaunchImageName</key>
                      <string>[email protected]</string>
                      <key>UILaunchImageOrientation</key>
                      <string>Portrait</string>
                      <key>UILaunchImageSize</key>
                      <string>{414, 736}</string>
              </dict>
      </array>
      <key>UILaunchStoryboardName</key>
      <string>SimpleSplash</string>
      <key>UIRequiredDeviceCapabilities</key>
      <array>
              <string>arm64</string>
      </array>
      <key>UIRequiresFullScreen</key>
      <true/>
      <key>UIStatusBarStyle</key>
      <string>UIStatusBarStyleDefault</string>
      <key>UISupportedInterfaceOrientations</key>
      <array>
              <string>UIInterfaceOrientationLandscapeRight</string>
      </array>
</dict>
</plist>
XML

  # <string>UIInterfaceOrientationPortrait</string>
  # <string>UIInterfaceOrientationLandscapeRight</string>

  info_plist_string.gsub!(":app_name", @app_name)
  info_plist_string.gsub!(":app_id", @app_id)

  $gtk.write_file_root "tmp/ios/#{@app_name}.app/Info.plist", info_plist_string.strip

  @info_plist_written = true
end

#device_orientation_xmlObject


920
921
922
923
# File 'dragon/ios_wizard.rb', line 920

def device_orientation_xml
  return "UIInterfaceOrientationLandscapeRight" if $gtk.logical_width > $gtk.logical_height
  return "UIInterfaceOrientationPortrait"
end

#do_zipObject


966
967
968
969
970
971
972
973
974
# File 'dragon/ios_wizard.rb', line 966

def do_zip
  $gtk.write_file_root "tmp/ios/do_zip.sh", <<-SCRIPT
pushd #{tmp_directory}/ipa_root/
zip -q -r archive.zip Payload
popd
SCRIPT

  sh "sh #{tmp_directory}/do_zip.sh"
end

#get_reserved_sprite(png) ⇒ Object


72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'dragon/ios_wizard.rb', line 72

def get_reserved_sprite png
  sprite_path = ".dragonruby/sprites/wizards/ios/#{png}"

  if !$gtk.ivar :rcb_release_mode
    sprite_path = "deploy_template/#{sprite_path}"
    $gtk.reset_sprite sprite_path
  end

  if !$gtk.read_file sprite_path
    log_error "png #{png} not found."
  end

  sprite_path
end

#idevice_id_cli_appObject


396
397
398
# File 'dragon/ios_wizard.rb', line 396

def idevice_id_cli_app
  "idevice_id"
end

#init_wizard_statusObject


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'dragon/ios_wizard.rb', line 168

def init_wizard_status
  @wizard_status = {}
  steps.each do |m|
    @wizard_status[m] = { result: :not_started }
  end

  previous_step = nil
  next_step = nil
  steps.each_cons(2) do |current_step, next_step|
    @wizard_status[current_step][:next_step] = next_step
  end

  steps.reverse.each_cons(2) do |current_step, previous_step|
    @wizard_status[current_step][:previous_step] = previous_step
  end
end

990
991
992
993
994
995
# File 'dragon/ios_wizard.rb', line 990

def print_publish_help
    log_info "Go to https://appstoreconnect.apple.com/apps and create an App if you haven't already done so."
    log_info "Go to https://appleid.apple.com and create a 'Application Specific Password'."
    log_info "To upload your app, Download Transporter from the App Store https://apps.apple.com/us/app/transporter/id1450874784?mt=12."
    log_info "Your app is located at ./tmp/ios/#{@app_name}.ipa"
end

#production_write_info_plistObject


766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
# File 'dragon/ios_wizard.rb', line 766

def production_write_info_plist
  log_info "Adding Info.plist."

  info_plist_string = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
      <key>BuildMachineOSBuild</key>
      <string>20D91</string>
      <key>CFBundleDevelopmentRegion</key>
      <string>en</string>
      <key>CFBundleDisplayName</key>
      <string>:app_name</string>
      <key>CFBundleExecutable</key>
      <string>Runtime</string>
      <key>CFBundleIconFiles</key>
      <array>
              <string>AppIcon60x60</string>
      </array>
      <key>CFBundleIcons</key>
      <dict>
              <key>CFBundlePrimaryIcon</key>
              <dict>
                      <key>CFBundleIconFiles</key>
                      <array>
                              <string>AppIcon60x60</string>
                      </array>
                      <key>CFBundleIconName</key>
                      <string>AppIcon</string>
              </dict>
      </dict>
      <key>CFBundleIcons~ipad</key>
      <dict>
              <key>CFBundlePrimaryIcon</key>
              <dict>
                      <key>CFBundleIconFiles</key>
                      <array>
                              <string>AppIcon60x60</string>
                              <string>AppIcon76x76</string>
                              <string>AppIcon83.5x83.5</string>
                      </array>
                      <key>CFBundleIconName</key>
                      <string>AppIcon</string>
              </dict>
      </dict>
      <key>CFBundleIdentifier</key>
      <string>:app_id</string>
      <key>CFBundleInfoDictionaryVersion</key>
      <string>6.0</string>
      <key>CFBundleName</key>
      <string>:app_name</string>
      <key>CFBundlePackageType</key>
      <string>APPL</string>
      <key>CFBundleShortVersionString</key>
      <string>:version</string>
      <key>CFBundleSignature</key>
      <string>????</string>
      <key>CFBundleSupportedPlatforms</key>
      <array>
              <string>iPhoneOS</string>
      </array>
      <key>CFBundleVersion</key>
      <string>:version</string>
      <key>DTCompiler</key>
      <string>com.apple.compilers.llvm.clang.1_0</string>
      <key>DTPlatformBuild</key>
      <string>18D46</string>
      <key>DTPlatformName</key>
      <string>iphoneos</string>
      <key>DTPlatformVersion</key>
      <string>14.4</string>
      <key>DTSDKBuild</key>
      <string>18D46</string>
      <key>DTSDKName</key>
      <string>iphoneos14.4</string>
      <key>DTXcode</key>
      <string>0124</string>
      <key>DTXcodeBuild</key>
      <string>12D4e</string>
      <key>MinimumOSVersion</key>
      <string>14.4</string>
      <key>UIAppFonts</key>
      <array/>
      <key>UIBackgroundModes</key>
      <array/>
      <key>UIDeviceFamily</key>
      <array>
              <integer>1</integer>
              <integer>2</integer>
      </array>
      <key>UILaunchImages</key>
      <array>
              <dict>
                      <key>UILaunchImageMinimumOSVersion</key>
                      <string>7.0</string>
                      <key>UILaunchImageName</key>
                      <string>[email protected]</string>
                      <key>UILaunchImageOrientation</key>
                      <string>Portrait</string>
                      <key>UILaunchImageSize</key>
                      <string>{320, 568}</string>
              </dict>
              <dict>
                      <key>UILaunchImageMinimumOSVersion</key>
                      <string>7.0</string>
                      <key>UILaunchImageName</key>
                      <string>[email protected]</string>
                      <key>UILaunchImageOrientation</key>
                      <string>Portrait</string>
                      <key>UILaunchImageSize</key>
                      <string>{375, 667}</string>
              </dict>
              <dict>
                      <key>UILaunchImageMinimumOSVersion</key>
                      <string>7.0</string>
                      <key>UILaunchImageName</key>
                      <string>[email protected]</string>
                      <key>UILaunchImageOrientation</key>
                      <string>Portrait</string>
                      <key>UILaunchImageSize</key>
                      <string>{414, 736}</string>
              </dict>
      </array>
      <key>UILaunchStoryboardName</key>
      <string>SimpleSplash</string>
      <key>UIRequiredDeviceCapabilities</key>
      <array>
              <string>arm64</string>
      </array>
      <key>UIRequiresFullScreen</key>
      <true/>
      <key>UIStatusBarStyle</key>
      <string>UIStatusBarStyleDefault</string>
      <key>UISupportedInterfaceOrientations</key>
      <array>
              <string>UIInterfaceOrientationLandscapeRight</string>
      </array>
</dict>
</plist>
XML

  # <string>UIInterfaceOrientationPortrait</string>
  # <string>UIInterfaceOrientationLandscapeRight</string>

  info_plist_string.gsub!(":app_name", @app_name)
  info_plist_string.gsub!(":app_id", @app_id)
  info_plist_string.gsub!(":version", @version);

  $gtk.write_file_root "tmp/ios/#{@app_name}.app/Info.plist", info_plist_string.strip

  @info_plist_written = true
end

#provisioning_profile_path(environment) ⇒ Object


234
235
236
237
# File 'dragon/ios_wizard.rb', line 234

def provisioning_profile_path environment
  return "profiles/distribution.mobileprovision" if environment == :prod
  return "profiles/development.mobileprovision"
end

#provisioning_profile_xml(environment) ⇒ Object


258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'dragon/ios_wizard.rb', line 258

def provisioning_profile_xml environment
  xml = $gtk.read_file (provisioning_profile_path environment)
  scrubbed = xml.each_line.map do |l|
    if l.strip.start_with? "<"
      if l.start_with? '</plist>'
        '</plist>'
      elsif l.include? "Apple Inc."
        nil
      elsif l.include? '<data>'
        nil
      else
        l
      end
    else
      nil
    end
  end.reject { |l| !l }.join
  $gtk.parse_xml scrubbed
end

#relative_pathObject


21
22
23
# File 'dragon/ios_wizard.rb', line 21

def relative_path
  (File.dirname $gtk.binary_path)
end

#restartObject


185
186
187
188
# File 'dragon/ios_wizard.rb', line 185

def restart
  init_wizard_status
  start
end

#root_folderObject


933
934
935
# File 'dragon/ios_wizard.rb', line 933

def root_folder
  "#{relative_path}/#{$gtk.cli_arguments[:dragonruby]}"
end

#security_cli_appObject


400
401
402
# File 'dragon/ios_wizard.rb', line 400

def security_cli_app
  "/usr/bin/security"
end

#set_app_id(id) ⇒ Object


336
337
338
339
340
# File 'dragon/ios_wizard.rb', line 336

def set_app_id id
  log_info = "App Id set to: #{id}"
  @app_id = id
  start
end

#set_app_name(name) ⇒ Object


311
312
313
314
# File 'dragon/ios_wizard.rb', line 311

def set_app_name name
  @app_name = name
  start
end

#set_dev_profile(path) ⇒ Object


316
317
318
319
320
321
322
323
324
# File 'dragon/ios_wizard.rb', line 316

def set_dev_profile path
  if !$gtk.read_file path
    log_error "I couldn't find a development profile at #{path}."
    ask_for_dev_profile
  else
    @provisioning_profile_path = path
    start
  end
end

#sh(cmd) ⇒ Object


976
977
978
979
980
981
982
983
# File 'dragon/ios_wizard.rb', line 976

def sh cmd
  log_info cmd.strip
  result = `#{cmd}`
  if result.strip.length > 0
    log_info result.strip.each_line.map(&:strip).join("\n")
  end
  result
end

#stage_appObject


330
331
332
333
334
# File 'dragon/ios_wizard.rb', line 330

def stage_app
  log_info "Staging."
  sh "mkdir -p #{tmp_directory}"
  sh "cp -R #{relative_path}/dragonruby-ios.app \"#{tmp_directory}/#{@app_name}.app\""
end

#stage_native_libsObject


1011
1012
1013
1014
# File 'dragon/ios_wizard.rb', line 1011

def stage_native_libs
  sh "cp -r \"#{root_folder}/native/\" \"#{app_path}/native/\""
  sh "CODESIGN_ALLOCATE=\"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate\" /usr/bin/codesign -f -s \"#{@certificate_name}\" --entitlements #{tmp_directory}/Entitlements.plist \"#{tmp_directory}/#{@app_name}.app/native/ios-device/ext.dylib\""
end

#start(opts = {}) ⇒ Object


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
123
124
125
126
127
128
129
130
131
132
133
134
# File 'dragon/ios_wizard.rb', line 87

def start opts = {}
  @opts = opts

  unless $gtk.args.fn.eq_any? @opts[:env], :dev, :prod
    raise WizardException.new(
      "* $wizards.ios.start needs to be provided an environment option.",
      "** For development builds type: $wizards.ios.start env: :dev",
      "** For production builds type: $wizards.ios.start env: :prod"
    )
  end

  @production_build = (@opts[:env] == :prod)

  @version = determine_app_version @opts
  log_info "I will be using version: '#{@version}'" if @production_build

  @steps = steps_development_build
  @steps = steps_production_build if @production_build
  @certificate_name = nil
  init_wizard_status
  if @production_build
    log_info "Starting iOS Wizard so we can create a production build."
  else
    log_info "Starting iOS Wizard so we can deploy to your device."
  end
  @start_at = Kernel.global_tick_count
  steps.each do |m|
    log_info "Running step ~:#{m}~."
    result = (send m) || :success if @wizard_status[m][:result] != :success
    @wizard_status[m][:result] = result
    log_info "Running step ~:#{m}~ complete."
  end
  nil
rescue Exception => e
  if e.is_a? WizardException
    $console.log.clear
    $console.archived_log.clear
    log "=" * $console.console_text_width
    e.console_primitives.each do |p|
      $console.add_primitive p
    end
    log "=" * $console.console_text_width
  else
    log_error e.to_s
  end

  $console.set_command "$wizards.ios.start env: :#{@opts[:env]}"
end

#stepsObject


25
26
27
# File 'dragon/ios_wizard.rb', line 25

def steps
  @steps ||= []
end

#steps_development_buildObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'dragon/ios_wizard.rb', line 29

def steps_development_build
  [
    :check_for_xcode,
    :check_for_brew,
    :check_for_certs,
    :check_for_device,
    :check_for_dev_profile,
    :determine_team_identifier,
    :determine_app_name,
    :determine_app_id,
    :blow_away_temp,
    :stage_app,
    :development_write_info_plist,
    :write_entitlements_plist,
    :compile_icons,
    :create_payload_directory,
    :code_sign_payload,
    :create_ipa,
    :deploy
  ]
end

#steps_production_buildObject


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'dragon/ios_wizard.rb', line 51

def steps_production_build
  [
    :check_for_xcode,
    :check_for_brew,
    :check_for_certs,
    :check_for_distribution_profile,
    :determine_team_identifier,
    :determine_app_name,
    :determine_app_id,
    :blow_away_temp,
    :stage_app,
    :production_write_info_plist,
    :write_entitlements_plist,
    :compile_icons,
    :create_payload_directory,
    :code_sign_payload,
    :create_ipa,
    :print_publish_help
  ]
end

#team_identifier_from_provisioning_profile(environment) ⇒ Object


292
293
294
295
296
297
298
299
300
301
302
303
# File 'dragon/ios_wizard.rb', line 292

def team_identifier_from_provisioning_profile environment
  team_identifier_index = (provisioning_profile_xml environment)[:children][0][:children][0][:children][13][:children][0][:children][0][:data]

  (provisioning_profile_xml environment)[:children][0][:children][0][:children][13][:children].each.with_index do |node, i|
    if node[:children] && node[:children][0] && node[:children][0][:data] == "com.apple.developer.team-identifier"
      team_identifier_index = i
      break
    end
  end

  (provisioning_profile_xml environment)[:children].first[:children].first[:children][13][:children][team_identifier_index + 1][:children].first[:data]
end

#tmp_directoryObject


925
926
927
# File 'dragon/ios_wizard.rb', line 925

def tmp_directory
  "#{relative_path}/tmp/ios"
end

#valid_certsObject


408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'dragon/ios_wizard.rb', line 408

def valid_certs
  certs = sh("#{security_cli_app} -q find-identity -p codesigning -v").each_line.map do |l|
    if l.include?(")") && !l.include?("Developer ID") && (l.include?("Development") || l.include?("Distribution"))
      l.strip
    else
      nil
    end
  end.reject_nil.map do |l|
    number, id, name = l.split(' ', 3)
    name = name.gsub("\"", "") if name
    {
      number: 1,
      id: id,
      name: name
    }
  end
end

#write_entitlements_plistObject


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
# File 'dragon/ios_wizard.rb', line 436

def write_entitlements_plist
  if @production_build
    entitlement_plist_string = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
      <dict>
              <key>application-identifier</key>
              <string>:app_id</string>
              <key>beta-reports-active</key>
              <true/>
      </dict>
</plist>
XML
  else
    entitlement_plist_string = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
      <dict>
              <key>application-identifier</key>
              <string>:app_id</string>
              <key>get-task-allow</key>
              <true/>
      </dict>
</plist>
XML
  end

  log_info "Creating Entitlements.plist"

  $gtk.write_file_root "tmp/ios/Entitlements.plist", entitlement_plist_string.gsub(":app_id", "#{@team_name}.#{@app_id}").strip

  sh "/usr/bin/plutil -convert binary1 \"#{tmp_directory}/Entitlements.plist\""
  sh "/usr/bin/plutil -convert xml1 \"#{tmp_directory}/Entitlements.plist\""

  @entitlement_plist_written = true
end

#write_info_plist_distributionObject


484
485
486
487
488
489
490
491
492
493
494
495
496
497
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
# File 'dragon/ios_wizard.rb', line 484

def write_info_plist_distribution
  log_info "Adding Info.plist."

  <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
      <key>BuildMachineOSBuild</key>
      <string>20D91</string>
      <key>CFBundleDevelopmentRegion</key>
      <string>en</string>
      <key>CFBundleName</key>
      <string>:app_name</string>
      <key>CFBundleDisplayName</key>
      <string>A Dark Room</string>
      <key>CFBundleIdentifier</key>
      <string>:app_id</string>
      <key>CFBundleExecutable</key>
      <string>:app_name</string>
      <key>CFBundleInfoDictionaryVersion</key>
      <string>6.0</string>
      <key>CFBundlePackageType</key>
      <string>APPL</string>
      <key>CFBundleShortVersionString</key>
      <string>5.6</string>
      <key>CFBundleSignature</key>
      <string>????</string>
      <key>CFBundleVersion</key>
      <string>5.6</string>
      <key>CFBundleIcons</key>
      <dict>
          <key>CFBundlePrimaryIcon</key>
          <dict>
              <key>CFBundleIconName</key>
              <string>AppIcon</string>
              <key>CFBundleIconFiles</key>
              <array>
                  <string>AppIcon60x60</string>
              </array>
          </dict>
      </dict>
      <key>CFBundleIcons~ipad</key>
      <dict>
          <key>CFBundlePrimaryIcon</key>
          <dict>
              <key>CFBundleIconName</key>
              <string>AppIcon</string>
              <key>CFBundleIconFiles</key>
              <array>
                  <string>AppIcon60x60</string>
                  <string>AppIcon76x76</string>
                  <string>AppIcon83.5x83.5</string>
              </array>
          </dict>
      </dict>
      <key>UILaunchStoryboardName</key>
      <string>SimpleSplash</string>
      <key>UIRequiresFullScreen</key>
      <true/>
      <key>ITSAppUsesNonExemptEncryption</key>
      <false/>
      <key>UIRequiredDeviceCapabilities</key>
      <array>
          <string>arm64</string>
      </array>
      <key>MinimumOSVersion</key>
      <string>10.3</string>
      <key>CFBundleSupportedPlatforms</key>
      <array>
          <string>iPhoneOS</string>
      </array>
      <key>CFBundleIconFiles</key>
      <array>
          <string>AppIcon20x20</string>
          <string>AppIcon29x29</string>
          <string>AppIcon40x40</string>
          <string>AppIcon60x60</string>
      </array>
      <key>UIDeviceFamily</key>
      <array>
          <integer>1</integer>
          <integer>2</integer>
      </array>
      <key>UISupportedInterfaceOrientations</key>
      <array>
          <string>UIInterfaceOrientationPortrait</string>
      </array>
      <key>UIStatusBarStyle</key>
      <string>UIStatusBarStyleDefault</string>
      <key>UIBackgroundModes</key>
      <array>
      </array>
      <key>DTXcode</key>
      <string>0124</string>
      <key>DTXcodeBuild</key>
      <string>12D4e</string>
      <key>DTSDKName</key>
      <string>iphoneos14.4</string>
      <key>DTSDKBuild</key>
      <string>18D46</string>
      <key>DTPlatformName</key>
      <string>iphoneos</string>
      <key>DTCompiler</key>
      <string>com.apple.compilers.llvm.clang.1_0</string>
      <key>DTPlatformVersion</key>
      <string>14.4</string>
      <key>DTPlatformBuild</key>
      <string>18D46</string>
  </dict>
</plist>
XML
end

#write_ip_addressObject


937
938
939
# File 'dragon/ios_wizard.rb', line 937

def write_ip_address
  $gtk.write_file "app/server_ip_address.txt", $gtk.ffi_misc.get_local_ip_address.strip
end

#xcodebuild_cli_appObject


404
405
406
# File 'dragon/ios_wizard.rb', line 404

def xcodebuild_cli_app
  "xcodebuild"
end