如何根据构建配置更改应用程序传输安全设置?
How do you change App Transport Security Settings based on the build configuration?
我有一个具有多个构建配置的应用程序。如果选择的配置是 Debug,我希望 Info.plist
文件中的 NSAllowsArbitraryLoads 键设置为 YES,否则我希望将其设置为 NO。
我该如何实现?
我找到的解决方案需要使用PlistBuddy:
在您的项目设置中,select 构建阶段 > 单击 + 添加新的 运行 脚本构建阶段。
为阶段命名 "App Transport Security"。
粘贴以下脚本:
if [ "${CONFIGURATION}" = "Release" ];
then
/usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads false" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
else
/usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads true" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
fi
我有一个具有多个构建配置的应用程序。如果选择的配置是 Debug,我希望 Info.plist
文件中的 NSAllowsArbitraryLoads 键设置为 YES,否则我希望将其设置为 NO。
我该如何实现?
我找到的解决方案需要使用PlistBuddy:
在您的项目设置中,select 构建阶段 > 单击 + 添加新的 运行 脚本构建阶段。
为阶段命名 "App Transport Security"。 粘贴以下脚本:
if [ "${CONFIGURATION}" = "Release" ];
then
/usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads false" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
else
/usr/libexec/PlistBuddy -c "Set :NSAppTransportSecurity:NSAllowsArbitraryLoads true" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
fi