Xcode 构建设置 - 在生产构建时从 plist 中删除代码 [英] Xcode build settings - Remove code from plist on production build

查看:26
本文介绍了Xcode 构建设置 - 在生产构建时从 plist 中删除代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们关闭了 HTTPS 请求,并将它们作为 HTTP 发送,以便针对我本地机器上的 API 进行内部测试.为此,我将此代码添加到 info.plist

In our project we have turned off HTTPS requests and send them as HTTP for internal testing against an API on my local machine. To do this I added this code to the info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

这允许应用通过 HTTP 请求运行.显然,这对实时环境不利,而且不太可能获得应用商店的批准;所以我想在我们的生产构建目标中设置代码以自动删除这个有问题的代码,以免我们不小心把它留在里面.我已经做了一些搜索,但似乎无法在网上找到任何建议.

This allows the app to run with HTTP requests. Obviously this is bad for a live environment as well as unlikely to get app store approval; so I would like to set up code in our production build target to remove this offending code automatically lest we accidentally leave it in. I've done some searching around but can't seem to find any advice online.

推荐答案

添加用户定义的构建设置,例如 ALLOWS_ARBITARARY_LOADS 然后将其值更改为 YesNo 用于您的配置.然后更改 info plist 条目

Add a user defined build settings like ALLOWS_ARBITARARY_LOADS then change its value to Yes or No for your configurations. Then change the info plist entry

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <string>$(ALLOWS_ARBITARARY_LOADS)</string>
</dict>

注意:这里 NSAllowsArbitraryLoads 作为字符串添加,因为我们无法将布尔值或数字值 rom 构建设置添加到 plist.即使它是一个字符串,它的 bool 值在运行时也将是布尔值 Yes 或 No,因为 info plist 将作为字典.参考

Note: Here NSAllowsArbitraryLoads is added as a string since we cannot add boolean or number value rom build settings to plist. Even though it is a string its bool value will be boolean Yes or No in runtime since info plist is taking as a dictionary.Reference

这篇关于Xcode 构建设置 - 在生产构建时从 plist 中删除代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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