I figured this out. Turns out it was easier than I thought. I assumed that since it was an Array type that it would be harder than just adding a string, but it isn’t. I also realized as I studied the existing code in the above link that the info.plist file is just XML. XML I know well.
There are a couple of things to note. When looking at the values in Xcode they are spelled out at strings like Support external accessory protocols. In the XML the key is actually UISupportedExternalAccessoryProtocols. I found this out by putting in what I thought it should be and it didn’t work. I then opened the info.plist file in MonoDevelop and it shows the real key string.
You will probably also notice that I needed to add the UIBackgroundModes array as well.
Hope this saves someone else some time.
Here is my script:
#!/usr/bin/perl
use File::Copy;
print ("
*** Starting PostprocessBuildPlayer ***
");
my $installPath = $ARGV[0];
#go through the info.plist file line by line until you find this one:
my $endOfPlist = "</dict>";
# The type of player built:
# "dashboard", "standaloneWin32", "standaloneOSXIntel", "standaloneOSXPPC", "standaloneOSXUniversal", "webplayer", "iPhone"
my $target = $ARGV[1];
print ("
*** PostprocessBuildPlayer - Building at ‘$installPath’ with target: $target ***
");
################################################################
# This modifies info.plist to add the external accessory #
# entries #
################################################################
#open this file
$oplistPath = $installPath."/Info.plist";
$nplistPath = $installPath."/Info.plist.tmp";
open OLDPLIST, "<", $oplistPath or die("Cannot open Info.plist");
open NEWPLIST, ">", $nplistPath or die("Cannot create new Info.plist");
my $nextLine = 0;
while(<OLDPLIST>)
{
################################################################
# Add any key/value pairs you want at the end of Info.plist #
################################################################
if ($_ =~ m/$endOfPlist/)
{
my $keys = "";
$keys .= " <key>UISupportedExternalAccessoryProtocols</key>
";
$keys .= "
";
$keys .= " com.AmpedRFTech.Demo
";
$keys .= "
";
$keys .= " <key>UIBackgroundModes</key>
";
$keys .= "
";
$keys .= " App communicates with an accessory
";
$keys .= "
";
$_ = $keys . $_;
}
print NEWPLIST $_;
}
close OLDPLIST;
close NEWPLIST;
`mv \'$nplistPath\' \'$oplistPath\'`;