如何将 NSExceptionDomains 添加到 xcode 7.0.1 版的 plist?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32962155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:00:12  来源:igfitidea点击:

How to add NSExceptionDomains to plist of xcode Version 7.0.1?

iosxcodeplistios9xcode7

提问by Hyman

I would like to bundle a HTML based website as an iPhone app using Xcode Version 7.0.1, everything works fine and my only issue is that when I test the application on iPhone 4s, it wont show images that are accessed through http. However, I could access images of another website that provide httpsaccess to its images.

我想使用 Xcode 版本 7.0.1 将基于 HTML 的网站捆绑为 iPhone 应用程序,一切正常,我唯一的问题是当我在 iPhone 4s 上测试应用程序时,它不会显示通过http. 但是,我可以访问提供https对其图像的访问权限的另一个网站的图像。

Is there any way to add http support to the bundle?

有什么方法可以向包中添加 http 支持吗?

Update

更新

I added an NSExceptionDomainsto my plist file, but I still have the same issue

NSExceptionDomains在我的 plist 文件中添加了一个,但我仍然有同样的问题

<?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>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleDisplayName</key>
    <string>My Project</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIcons</key>
    <dict/>
    <key>CFBundleIcons~ipad</key>
    <dict/>
    <key>CFBundleIdentifier</key>
    <string>com.myproject.names</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>1.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0.1</string>
    <key>CFBundleSignature</key>
    <string>myproject</string>
    <key>CFBundleVersion</key>
    <string>1.1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>UIMainStoryboardFile</key>
    <string>Main_iPhone</string>
    <key>UIMainStoryboardFile~ipad</key>
    <string>Main_iPad</string>
    <key>UIRequiresFullScreen</key>
    <string>YES</string>
    <key>UIStatusBarHidden</key>
    <false/>
    <key>UIStatusBarStyle</key>
    <string>UIStatusBarStyleLightContent</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>appanalytics.embarcadero.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key><true/>
            </dict>
        </dict>
    </dict>
</dict>
</plist>

I also tried following based on this question

我也尝试过基于这个问题

<dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>mydomain.com</key>
            <dict>
                <!--Include to allow subdomains-->
                <key>NSIncludesSubdomains</key>
                <true/>
                <!--Include to allow HTTP requests-->
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <!--Include to specify minimum TLS version-->
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
        </dict>
    </dict>

Update

更新

I added the code mentioned in herebut still have the same issue.

我添加了这里提到的代码,但仍然有同样的问题。

Update

更新

As suggested, I changed the plist to following but still has the same issue. Also, I added http:// to values of key tags to no avail.

按照建议,我将 plist 更改为以下,但仍然存在相同的问题。此外,我将 http:// 添加到关键标签的值无济于事。

<?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>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleDisplayName</key>
    <string>My Project</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIcons</key>
    <dict/>
    <key>CFBundleIcons~ipad</key>
    <dict/>
    <key>CFBundleIdentifier</key>
    <string>com.myproject.names</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>1.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>3.1.6</string>
    <key>CFBundleSignature</key>
    <string>myproject</string>
    <key>CFBundleVersion</key>
    <string>1.2</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UIMainStoryboardFile</key>
    <string>Main_iPhone</string>
    <key>UIMainStoryboardFile~ipad</key>
    <string>Main_iPad</string>
    <key>UIRequiresFullScreen</key>
    <string>YES</string>
    <key>UIStatusBarHidden</key>
    <false/>
    <key>UIStatusBarStyle</key>
    <string>UIStatusBarStyleLightContent</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>myproject.com.ca</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
            <key>myproject.com.ca</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
</dict>
</plist>

回答by adurdin

Firstly, your Info.plist has two separate NSAppTransportSecurity key-value pairs. You should fix that so there is only the one pair.

首先,您的 Info.plist 有两个单独的 NSAppTransportSecurity 键值对。你应该解决这个问题,所以只有一对。

Your question doesn't say what domains your images are loaded from. It would be easier to give a specific answer if you could include this information.

您的问题没有说明您的图像是从哪些域加载的。如果您可以包含此信息,则更容易给出具体答案。

If, for example, your images are loaded from example.comor subdomains, you could add an exception as follows:

例如,如果您的图像是从example.com域或子域加载的,您可以按如下方式添加例外:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>appanalytics.embarcadero.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>example.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

If you don't know in advance what domains the images will be loaded from, then you can instead allows HTTP access to all domains:

如果您事先不知道图像将从哪些域加载,那么您可以改为允许 HTTP 访问所有域:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>appanalytics.embarcadero.com</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

Note that although the inclusion of appanalytics.embarcadero.comin this second example is technically redundant, it is recommended that you specify ATS exceptions for all known domains that your app will access.

请注意,尽管appanalytics.embarcadero.com在第二个示例中包含的内容在技​​术上是多余的,但建议您为应用程序将访问的所有已知域指定 ATS 例外。

回答by Gillsoft AB

You can read this tutorial on how to configure App Transport Securityor you could just allow everything as before by adding Dictionary "NSAppTransportSecurity" with a Boolean key named "NSAllowsArbitraryLoads" with the value "YES" in your info.plist.

您可以阅读有关如何配置应用程序传输安全性的本教程,或者您可以像以前一样通过在 info.plist 中添加带有名为“NSAllowsArbitraryLoads”的布尔键值“YES”的字典“NSAppTransportSecurity”来允许所有内容。

回答by blld

Your key name is NSExceptionAllowsInsecureHTTPLoadsbut it should be NSTemporaryExceptionAllowsInsecureHTTPLoads

您的密钥名称是NSExceptionAllowsInsecureHTTPLoads但应该是NSTemporaryExceptionAllowsInsecureHTTPLoads

Also, did you try to add

另外,您是否尝试添加

<key>NSExceptionRequiresForwardSecrecy</key>
<false/>

to ATS domain's key?
Some domains requires it.

到 ATS 域的密钥?
某些域需要它。