我们的团队正在开发一个应用程序,我想添加一些主屏幕快速操作,仅用于调试目的。此外,我希望在全新安装后立即启用它,这意味着动态快速操作将不是一个选项。但是,我不知道我们是否只能在调试模式下启用静态快速操作。有什么办法可以做到这一点?
问问题
127 次
2 回答
2
为此,您有两个主要选择:
- 任何类型文件的 GENERAL 选项:
最简洁的方法是为每个配置设置单独的文件。然后:
- 您可以在项目构建设置中为每个配置设置路径,如下所示:
或者,您可以为此使用运行脚本或在构建过程中需要更改的任何文件:
- 创建两个不同
info.plist
的文件,一个用于调试,另一个用于生产 - 前往项目构建设置并创建新的运行脚本阶段
- 使用以下脚本:
- 创建两个不同
sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/"
debugFileName="Debug-Info.plist"
releaseFileName="Release-Info.plist"
if [ "$CONFIGURATION" == "Debug" ]; then
cp $sourceFilePath/$debugFileName "$INFOPLIST_FILE"
else
cp $sourceFilePath/$releaseFileName "$INFOPLIST_FILE"
fi
请注意,在此示例中:
- 我使用Debug-Info.plist作为调试模式文件。
- 我使用Release-Info.plist作为发布模式文件。
- 我将所有文件复制到与原始文件相同的目录中
info.plist
。
但是我制作了所有变量,您可以将它们更改为您想要的任何内容。
- 任何plist
文件的更具体选项:
由于Info.plist
是一个属性列表,您可以使用PlistBuddy直接编辑它的任何值。以下是仅在调试模式下添加快捷方式项的示例脚本:
/usr/libexec/PlistBuddy -c "Delete :UIApplicationShortcutItems" "$INFOPLIST_FILE"
if [ "$CONFIGURATION" != "Debug" ]; then
exit
fi
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems array" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "delete :UIApplicationShortcutItems" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems array" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0 dict" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemIconType string UIApplicationShortcutIconTypePlay" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemTitle string Play" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemSubtitle string Start playback" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemType string PlayMusic" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemUserInfo dict" "$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "add :UIApplicationShortcutItems:0:UIApplicationShortcutItemUserInfo:firstShortcutKey1 string firstShortcutKeyValue1" "$INFOPLIST_FILE"
记得在之前 的某个时间运行这个脚本Copy Bundle Resources
。
我建议您始终将脚本代码放在单独的文件中,并在构建阶段调用它。
于 2019-08-03T14:28:11.820 回答
0
显然,问题在于您要求Info.plist 中的条目存在于调试配置中,而不是发布配置中。Info.plist的内容不会根据配置自动来去去去。但是使用什么文件作为Info.plist可以根据配置进行更改,因为它只是一个构建设置。所以解决这个问题的一种方法是一个特殊的配置和一个特殊的Info.plist来配合它。
于 2019-08-03T13:59:03.867 回答