【发布时间】:2016-07-26 15:26:13
【问题描述】:
安全设置似乎是正确的,但我的 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
【问题讨论】:
-
这周刚开始发生在我身上。 iOS 10.2 及更高版本似乎正在发生这种情况。我会注意到,最新的文档中,键名中不再使用“临时”一词。 developer.apple.com/library/content/documentation/General/… 但是,更正键名并不能解决问题。该应用似乎忽略了域列表。
标签: ios xcode security react-native plist