将许可证部分添加到iOS设置包的最佳方法 [英] best way to add license section to iOS settings bundle

查看:88
本文介绍了将许可证部分添加到iOS设置包的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iOS应用程序使用许多在Apache 2.0和类似许可下获得许可的第三方组件,这要求我包含各种文本,这类事情:

My iOS application uses a number of third party components licensed under Apache 2.0 and similar licenses, which requires me to include various bits of text, this kind of thing:

* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

将此信息置于设置包中的许可子条目下似乎是一个合理的先例(在ipad facebook,页面,主题演讲,数字和wikipanion似乎都这样做了。)

There seems to be a reasonable precedent for putting this information under a 'License' subentry in settings bundle (on the ipad facebook, pages, keynote, numbers and wikipanion all seem to do this).

我努力实现同样的努力;我似乎需要逐行拆分文本并一次输入xcode一行(编辑plist时xcode4似乎有崩溃问题)。

I'm struggling a bit to actually achieve the same though; I seem to need to split the text up line by line and enter into xcode a line at a time (and xcode4 seems to have a crashing problem when editing the plists).

看起来几乎可以肯定某个地方要做的事情,或者我错过了一些简单的方法。

It seems like the kind of thing that there's almost certainly a somewhere script to do, or some simple way to do it that I've missed.

推荐答案

我想我现在已经设法解决了我遇到的所有问题。

I think I've now managed to solve all the problems I was running into.


  • 这似乎是最好的使用组元素标题来保存许可证(这是Apple在iWork应用程序中执行的操作)。但是这些的长度是有限制的(我还没有确切地知道限制是什么),所以你需要将每个许可文件分成多个字符串。

  • 你可以通过包含文字回车(即,也称为^ M,\r或0x0A)来创建换行符。

  • 确保不包含任何文字的中间文本如果你这样做,文件中的部分或全部字符串将被静默忽略。

我有一个便利脚本我用于帮助生成.plist和.strings文件,如下所示。

I've got a convenience script I use to help generate the .plist and .strings file, shown below.

使用它:


  1. 在项目下创建许可证目录

  2. 将脚本放入该目录

  3. 将每个许可证放入该目录,一个每个文件,文件名以.license结尾

  4. 对许可证执行任何必要的重新格式化(例如,删除行开头的额外空格,确保段落中没有换行符) )。每个段落之间应该有一个空行

  5. 更改为许可证目录&运行脚本

  6. 编辑您的设置包Root.plist以包含一个名为'Acknowledments'的子部分

  1. Create a 'licenses' directory under your project
  2. Put script into that directory
  3. Put each license into that directory, one per file, with filenames that end .license
  4. 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
  5. Change to licenses directory & run the script
  6. Edit your settings bundle Root.plist to include a child section called 'Acknowledgements'

这是脚本:

#!/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';
<?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>StringsTable</key>
        <string>Acknowledgements</string>
        <key>PreferenceSpecifiers</key>
        <array>
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";
                <dict>
                        <key>Type</key>
                        <string>PSGroupSpecifier</string>
                        <key>Title</key>
                        <string>$keynum</string>
                </dict>
EOD

        print $outfh "\"$keynum\" = \"$str\";\n";
        $keynum = $key.(++$cnt);
    }
}

print $plistfh <<'EOD';
        </array>
</dict>
</plist>
EOD
close($outfh);
close($plistfh);



设置您的Settings.bundle



如果你有的话没有创建一个Settings.bundle,转到文件 - >新建 - >新文件...

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.

展开 Settings.bundle 组并选择 Root.plist 。您需要添加一个新部分,其键将是类型数组的首选项。添加以下信息:

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:

文件名键指向此脚本创建的plist。您可以将标题更改为您想要的内容。

The Filename key points to the plist that was created by this script. You can change the title to what ever you want.

此外,如果您希望在构建项目时运行此脚本,则可以向目标添加构建阶段:

Also, if you want this script to run whenever you build your project, you can add a build phase to your target:


  1. 转到您的项目文件

  2. 选择目标

  3. 单击Build Phases选项卡

  4. 在该窗格的右下角,单击添加构建阶段

  5. 选择添加运行脚本

  6. 拖放将perl脚本放入脚本部分。修改看起来像这样:

  1. Go to your project file
  2. Select the target
  3. Click the Build Phases tab
  4. In the lower right corner of that pane, click on 'Add Build Phase'
  5. Select 'Add Run Script'
  6. Drag and drop your perl script into the section for your script. Modify to look something like this:





  1. cd $ SRCROOT / licenses $ SRCROOT 指向项目的根目录)

  2. ./ yourScriptName.pl

  1. cd $SRCROOT/licenses ($SRCROOT points to the root of your project)
  2. ./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.

iOS 7更新: iOS 7似乎处理标题键不同,并且正在弄乱渲染文本。要解决这个问题,生成的Acknowledgements.plist需要使用FooterText键而不是Title。这个如何更改脚本:

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";
            <dict>
                    <key>Type</key>
                    <string>PSGroupSpecifier</string>
                    <key>FooterText</key> # <= here is the change
                    <string>$keynum</string>
            </dict>
 EOD

    print $outfh "\"$keynum\" = \"$str\";\n";
    $keynum = $key.(++$cnt);
}

这篇关于将许可证部分添加到iOS设置包的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆