best way to add license section to iOS settings bundle
I think I've now managed to solve all the problems I was running into.
- It seems to be best to use group element titles to hold the licenses (this is what Apple do in the iWork apps). There is however a limit on the length of these (and I've not yet discovered exactly what the limit is), so you need to break each license file into multiple strings.
- You can create a line break within these by include a literal carriage return (ie. otherwise known as ^M, \r or 0x0A)
- Make sure not to include any literal "s mid-text. If you do, some or all of the strings in the file will get silently ignored.
I've got a convenience script I use to help generate the .plist and .strings file, shown below.
To use it:
- Create a 'licenses' directory under your project
- Put script into that directory
- Put each license into that directory, one per file, with filenames that end .license
- Perform any necessary reformatting on the licenses. (eg. remove extra spaces at the beginning of lines, ensure that there are no line breaks mid-paragraph). There should be a blank line in-between each paragraph
- Change to licenses directory & run the script
- Edit your settings bundle Root.plist to include a child section called 'Acknowledgements'
Here's the script:
#!/usr/bin/perl -w
use strict;
my $out = "../Settings.bundle/en.lproj/Acknowledgements.strings";
my $plistout = "../Settings.bundle/Acknowledgements.plist";
unlink $out;
open(my $outfh, '>', $out) or die $!;
open(my $plistfh, '>', $plistout) or die $!;
print $plistfh <<'EOD';
StringsTable
Acknowledgements
PreferenceSpecifiers
EOD
for my $i (sort glob("*.license"))
{
my $value=`cat $i`;
$value =~ s/\r//g;
$value =~ s/\n/\r/g;
$value =~ s/[ \t]+\r/\r/g;
$value =~ s/\"/\'/g;
my $key=$i;
$key =~ s/\.license$//;
my $cnt = 1;
my $keynum = $key;
for my $str (split /\r\r/, $value)
{
print $plistfh <<"EOD";
Type
PSGroupSpecifier
Title
$keynum
EOD
print $outfh "\"$keynum\" = \"$str\";\n";
$keynum = $key.(++$cnt);
}
}
print $plistfh <<'EOD';
EOD
close($outfh);
close($plistfh);
Setting up your Settings.bundle
If you haven't created a Settings.bundle, go to File --> New --> New File...
Under the Resource section, find the Settings Bundle. Use the default name and save it to the root of your project.
Expand the Settings.bundle
group and select Root.plist
. You will need to add a new section where its key will be Preference Items
of type Array
. Add the following information:
The Filename
key points to the plist that was created by this script. You can change the title
to what ever you want.
Execute Script At Build Time
Also, if you want this script to run whenever you build your project, you can add a build phase to your target:
- Go to your project file
- Select the target
- Click the Build Phases tab
- In the lower right corner of that pane, click on 'Add Build Phase'
- Select 'Add Run Script'
- Drag and drop your perl script into the section for your script. Modify to look something like this:
cd $SRCROOT/licenses
($SRCROOT
points to the root of your project)./yourScriptName.pl
After you have finished that, you can drag the Run Script
build phase sooner in the build process. You'll want to move it up before Compile Sources
so that the updates to your Settings Bundle get compiled and copied over.
Update for iOS 7: iOS 7 seems to handle the "Title" key different and is messing up the rendered text. To fix that the generated Acknowledgements.plist needs to use the "FooterText" key instead of "Title". This how to change the script:
for my $str (split /\r\r/, $value)
{
print $plistfh <<"EOD";
Type
PSGroupSpecifier
FooterText # <= here is the change
$keynum
EOD
print $outfh "\"$keynum\" = \"$str\";\n";
$keynum = $key.(++$cnt);
}
What's the proper way to include license text in Settings app under iOS 7?
Before iOS 7 you could set the license as the title of a group. By replacing "Title" with "FooterText" the issue in iOS 7 can be solved:
"Type" - String - "PSGroupSpecifier"
"FooterText" - String - Your license
Is it possible to add info or help text to an iPhone settings bundle?
According to recently changed Apple document, a FooterText key is available in PSGroupSpecifier dictionary, which is only available in iOS 4.0 or later.
Reference:
https://developer.apple.com/library/content/documentation/PreferenceSettings/Conceptual/SettingsApplicationSchemaReference/Articles/PSGroupSpecifier.html
Related Topics
How Does View Controller Containment Work in iOS 5
Are There APIs For Custom Vibrations in Ios
How to Support Universal Links in iOS App and Setup Server For It
Swiftui | Using Ondrag and Ondrop to Reorder Items Within One Single Lazygrid
How to Animate the Background Color of a Uilabel
Detect iOS App Entering Background
Using Nsuserdefaults on Arrays
How to Validate an E-Mail Address in Swift
Uicollectionview Inside a Uitableviewcell - Dynamic Height
Ios Universal Links Are Not Opening In-App
Shouldautorotatetointerfaceorientation Not Being Called in iOS 6
Swiftui - How to Pass Environmentobject into View Model