iOS 应用程序传输安全:允许 Info.plist 中的某些 IP 地址
iOS app transport security: Allow certain IP addresses in Info.plist
安全设置似乎是正确的,但出于某种原因我的 React Native 应用程序没有连接到服务器(无论是 运行 在 iOS 设备或模拟器上)。
服务器(ip地址和端口)在网络上可见,所以错误可能是Info.plist
里面的NSAppTransportSecurity
引起的。重启也没用。
一个可行的解决方案是将 NSAllowsArbitraryLoads
设置为 true
以打开地址。据我所知,它会暴露所有 IP 地址,因此应该避免。
NSExceptionDomains
似乎只适用于域名而不适用于 IP 地址。
如何打开 10.10.0.16
和 localhost
IP 地址并阻止所有其他地址?
应用程序传输安全设置:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>10.10.0.16</key>
<dict>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>localhost</key>
<dict>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
控制台日志:
2016-07-26 17:14:26.803 RNProject[80649:678556] NSMainNibFile and UIMainStoryboardFile are both set. NSMainNibFile ignored.
2016-07-26 17:14:26:936 RNProject[80649:678556] styleString = styleFile
2016-07-26 17:14:27.005 RNProject[80649:678837] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
2016-07-26 17:14:27.021 RNProject[80649:678556] INFO: Reveal Server started (Protocol Version 25).
2016-07-26 17:14:27.035 RNProject[80649:678556] Reachability: Reachable via WiFi
2016-07-26 17:14:27.035 RNProject[80649:678556] Reach = Reachability: Reachable via WiFi
2016-07-26 17:14:27.036 [fatal][tid:main] Could not connect to development server.
Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate
URL: http://10.10.0.16:8081/index.ios.bundle?platform=ios&dev=true
貌似唯一的解决办法就是在开发版中设置<key>NSAllowsArbitraryLoads</key><true/>
加载React Native库,在release中关闭
安全设置似乎是正确的,但出于某种原因我的 React Native 应用程序没有连接到服务器(无论是 运行 在 iOS 设备或模拟器上)。
服务器(ip地址和端口)在网络上可见,所以错误可能是Info.plist
里面的NSAppTransportSecurity
引起的。重启也没用。
一个可行的解决方案是将 NSAllowsArbitraryLoads
设置为 true
以打开地址。据我所知,它会暴露所有 IP 地址,因此应该避免。
NSExceptionDomains
似乎只适用于域名而不适用于 IP 地址。
如何打开 10.10.0.16
和 localhost
IP 地址并阻止所有其他地址?
应用程序传输安全设置:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>10.10.0.16</key>
<dict>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>localhost</key>
<dict>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
控制台日志:
2016-07-26 17:14:26.803 RNProject[80649:678556] NSMainNibFile and UIMainStoryboardFile are both set. NSMainNibFile ignored.
2016-07-26 17:14:26:936 RNProject[80649:678556] styleString = styleFile
2016-07-26 17:14:27.005 RNProject[80649:678837] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
2016-07-26 17:14:27.021 RNProject[80649:678556] INFO: Reveal Server started (Protocol Version 25).
2016-07-26 17:14:27.035 RNProject[80649:678556] Reachability: Reachable via WiFi
2016-07-26 17:14:27.035 RNProject[80649:678556] Reach = Reachability: Reachable via WiFi
2016-07-26 17:14:27.036 [fatal][tid:main] Could not connect to development server.
Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate
URL: http://10.10.0.16:8081/index.ios.bundle?platform=ios&dev=true
貌似唯一的解决办法就是在开发版中设置<key>NSAllowsArbitraryLoads</key><true/>
加载React Native库,在release中关闭