在native native

时间:2018-03-20 15:57:46

标签: javascript ios react-native

我遇到的问题是我编辑时的问题 的 MyProject的/ IOS / info.plist中 ,我成功保存了它。但是当我尝试打开项目以查看是否已应用更改时,它只会被编辑回其默认格式。有谁知道为什么会发生这种情况,如何在添加任何东西后进行明确的编辑? 在这里,您可以了解我的工作内容:

的package.json:

{
  "name": "user",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "npm": "^5.7.1",
    "react": "16.3.0-alpha.2",
    "react-native": "0.54.2"
  },
  "devDependencies": {
    "babel-jest": "23.0.0-alpha.0",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.2",
    "react-test-renderer": "16.3.0-alpha.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

编辑前

info.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>LastAccessedDate</key>
	<date>2018-03-20T15:02:01Z</date>
	<key>WorkspacePath</key>
	<string>/Users/user/Documents/myproject/ios/myproject.xcodeproj</string>
</dict>
</plist>

编辑后

info.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>LastAccessedDate</key>
    <date>2018-03-20T15:02:01Z</date>
    <key>WorkspacePath</key>
    <string>/Users/user/Documents/myproject/ios/myproject.xcodeproj</string>
</dict>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
</plist>

我解释一下,在保存所做的更改并从头开始重新编译应用程序时,info.plist中添加的行将消失,只保留默认值。

但是,如果没有解决方案,我可以添加什么而不是

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

向IOS设备提出http请求,有不同的方法吗?

1 个答案:

答案 0 :(得分:0)

文件中只应有一个根级别字典。所以试试这个:

<?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>LastAccessedDate</key>
    <date>2018-03-20T15:02:01Z</date>
    <key>WorkspacePath</key>
    <string>/Users/user/Documents/myproject/ios/myproject.xcodeproj</string>
    <key>NSAppTransportSecurity</key>
    <dict>
       <key>NSAllowsArbitraryLoads</key>
       <true/>
    </dict>
</dict>
</plist>