Jos*_*phH 114 plist ios settings.bundle
我的iOS应用程序使用许多在Apache 2.0和类似许可下许可的第三方组件,这要求我包含各种文本,这类事情:
* 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.
Run Code Online (Sandbox Code Playgroud)
将这些信息置于设置包中的"许可"子条目下似乎有一个合理的先例(在ipad facebook,页面,主题演讲,数字和wikipanion上似乎都这样做).
我努力实现同样的努力; 我似乎需要逐行拆分文本并一次输入xcode一行(并且xcode4在编辑plist时似乎有崩溃问题).
看起来几乎可以肯定是某个地方要做的事情,或者是我错过了一些简单的方法.
Jos*_*phH 192
我想我现在已经设法解决了我遇到的所有问题.
我有一个方便脚本,用于帮助生成.plist和.strings文件,如下所示.
要使用它:
这是脚本:
#!/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);
Run Code Online (Sandbox Code Playgroud)
如果您尚未创建Settings.bundle,请转到文件 - >新建 - >新建文件...
在"资源"部分下,找到"设置包".使用默认名称并将其保存到项目的根目录.
展开Settings.bundle
组并选择Root.plist
.您需要添加一个新的部分,其中键Preference Items
的类型Array
.添加以下信息:
该Filename
关键点,是由该脚本创建的plist中.您可以将其更改为title
您想要的任何内容.
此外,如果您希望在构建项目时运行此脚本,则可以向目标添加构建阶段:
cd $SRCROOT/licenses
($SRCROOT
指向项目的根目录)./yourScriptName.pl
完成后,您可以Run Script
在构建过程中更快地拖动构建阶段.您需要先将其移动,Compile Sources
以便编辑和复制您的设置包的更新.
iOS 7的更新: iOS 7似乎处理不同的"标题"键并且正在弄乱渲染的文本.要解决这个问题,生成的Acknowledgements.plist需要使用"FooterText"键而不是"Title".这个如何更改脚本:
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);
}
Run Code Online (Sandbox Code Playgroud)
Sea*_*ean 36
这是@JosephH提供的相同解决方案(没有翻译),但是在Python中为任何喜欢python over perl的人完成
import os
import sys
import plistlib
from copy import deepcopy
os.chdir(sys.path[0])
plist = {'PreferenceSpecifiers': [], 'StringsTable': 'Acknowledgements'}
base_group = {'Type': 'PSGroupSpecifier', 'FooterText': '', 'Title': ''}
for filename in os.listdir("."):
if filename.endswith(".license"):
current_file = open(filename, 'r')
group = deepcopy(base_group)
title = filename.split(".license")[0]
group['Title'] = title
group['FooterText'] = current_file.read()
plist['PreferenceSpecifiers'].append(group)
plistlib.writePlist(
plist,
"../Settings.bundle/Acknowledgements.plist"
)
Run Code Online (Sandbox Code Playgroud)
Jos*_*phH 15
作为替代方案,对于那些使用CocoaPods的人,它将为Podfile中指定的每个目标生成一个"Acknowledgements"plist,其中包含该目标中使用的每个Pod的许可证详细信息(假设已在Pod规范中指定了详细信息).可以添加到iOS设置包的属性列表文件.
还有正在进行的项目允许在应用程序中转换和显示此数据:
https://github.com/CocoaPods/cocoapods-install-metadata
https://github.com/cocoapods/CPDAcknowledgements
car*_*loe 14
我以为我会把我的迭代扔在Sean的混合中很棒的python代码上.主要区别在于它需要一个输入目录,然后以递归方式搜索它以获取LICENSE文件.它从LICENSE文件的父目录派生标题值,因此它可以很好地与cocoapods一起使用.
我的动机是创建一个构建脚本,以便在我添加或删除pod时自动保持我的应用程序的合法部分是最新的.它还执行其他一些操作,例如从许可证中删除强制换行符,以便段落在设备上看起来更好一些.
https://github.com/carloe/LicenseGenerator-iOS
我在Ruby编写了一个由@JosephH脚本激发的脚本.在我看来,这个版本将更好地代表各个开源项目.
Wisit iOS-AcknowledgementGenerator下载脚本和示例项目.
这是您的应用程序中的确认:
归档时间: |
|
查看次数: |
42543 次 |
最近记录: |