2

Here is my component code..

render() {
    return (
      <WebView
        source={{uri: 'http://qq.com'}}
        style={{marginTop: 20}}
      />
    );
  }

Here is my info.plist code for "NSAppTransportSecurity"

    <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>qq.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>

When I run

react-native run-ios

The simulator shows error

enter image description here

How to fix it? (using RN 0.40 version)

Dreams
  • 8,288
  • 10
  • 45
  • 71
  • 1
    Possible duplicate of [The resource could not be loaded because the App Transport Security policy requires the use of a secure connection](http://stackoverflow.com/questions/32631184/the-resource-could-not-be-loaded-because-the-app-transport-security-policy-requi) – Bista Jan 25 '17 at 16:18

3 Answers3

8

you need this in your info.plist to do a http request

enter image description here

breno
  • 230
  • 2
  • 15
  • This is really dangerous as it allows for any hosts! It should limited to the host/IP address. – ZedTuX Jul 11 '18 at 13:43
4

You set up an exception domain but you didn't actually define any exception in it. You have to tell it what setting you want to be different for that domain. Your plist should look like:

<key>NSAppTransportSecurity</key>
    <dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>qq.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
dan
  • 9,695
  • 1
  • 42
  • 40
  • 1
    Thanks. I added it to info.plist file and refresh the simulator but still have same error. : ( – Dreams Jan 25 '17 at 14:56
  • I switched it to a different key. The other one might not work in an exception domain. – dan Jan 25 '17 at 15:01
2

First of all, you should not use NSAllowsArbitraryLoads key alone because you will almost definitely be rejected by Apple in application review in the future.

I think it is the simplest configuration to show http://qq.com completely. NSAllowsArbitraryLoadsInWebContent key can be affected only to iOS 10+, so you have to add also NSAllowsArbitraryLoads if you want to support iOS 9 or earlier.

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

If you want to know further details, I recommend you refer to the official document:
https://developer.apple.com/library/prerelease/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html

See also:
https://developer.apple.com/news/?id=12212016b

At WWDC 2016 we announced that apps submitted to the App Store will be required to support ATS at the end of the year. To give you additional time to prepare, this deadline has been extended and we will provide another update when a new deadline is confirmed.

What I meant future was this deadline.

Toru
  • 517
  • 1
  • 5
  • 19