Created
January 30, 2018 05:19
-
-
Save deze333/d4759dd58d7b3b4d76b7cdc12aa93e91 to your computer and use it in GitHub Desktop.
Cocoapods post install script that ensures NSPrincipalClass is copied across to Info.plist of nominated pods. Without this NSPrincipalClass will be nil.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Post install script that ensures that NSPrincipalClass | |
| # is transferred from original info.plist to the pod generated info.plist. | |
| post_install do |installer| | |
| # Frameworks and their principal classes dictionary | |
| frameworks_classes = { | |
| 'FrameworkA' => 'FrameworkAPrincipalClassName', | |
| 'FrameworkB' => 'FrameworkBPrincipalClassName' | |
| } | |
| # Scan directory tree | |
| frameworks_classes.each do |framework_name, framework_class| | |
| directory = installer.config.project_pods_root | |
| Dir.foreach(directory) do |path| | |
| if path.to_s == 'Target Support Files' | |
| full_path = directory + path | |
| if File.directory?(full_path) | |
| puts full_path | |
| Dir.foreach(full_path) do |path2| | |
| if path2.to_s == framework_name | |
| full_path = full_path + path2 | |
| Dir.foreach(full_path) do |path3| | |
| if path3.to_s == 'Info.plist' | |
| info_plist_path = full_path + path3 | |
| # Open Info.plist and modify it | |
| if File.exist?(info_plist_path) | |
| text = File.read(info_plist_path) | |
| new_contents = text.gsub(/(<key>NSPrincipalClass<\/key>\s*<string>)()(<\/string>)/, '\1' + framework_class + '\3') | |
| File.open(info_plist_path, "w") {|file| file.puts new_contents } | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment