iOS swift:App Transport Security阻止了一个明文HTTP(http://)资源

时间:2016-10-23 19:06:17

标签: ios swift api https

晚上,我正在开发基于SWAPI的应用程序(星球大战api:https://swapi.co/documentation

我得到了 ATS错误struct node{ int key; vector<int> values; }; class key_value_sequences { public: key_value_sequences() { } ~key_value_sequences() { } key_value_sequences(const key_value_sequences& A) { myList = A.myList; v = A.v; } key_value_sequences& operator=(const key_value_sequences& A) { if (this == &A) return *this; myList = A.myList; v = A.v; return *this; } // YOU SHOULD USE C++ CONTAINERS TO AVOID RAW POINTERS // IF YOU DECIDE TO USE POINTERS, MAKE SURE THAT YOU MANAGE MEMORY PROPERLY // IMPLEMENT ME: SHOULD RETURN SIZE OF A SEQUENCE FOR GIVEN KEY // IF NO SEQUENCE EXISTS FOR A GIVEN KEY RETURN -1 int size(int key) const { if (find(v.begin(), v.end(), key)!=v.end()) { for(list<node>::iterator it = myList.begin(); it != myList.end(); it++) { if (it->key == key) { return it->values.size(); } } } else return -1; } // IMPLEMENT ME: SHOULD RETURN POINTER TO A SEQUENCE FOR GIVEN KEY // IF NO SEQUENCE EXISTS FOR A GIVEN KEY RETURN nullptr const int* data(int key) const { if (find(v.begin(), v.end(), key)!=v.end()) { for(list<node>::iterator it = myList.begin(); it != myList.end(); it++) { if (it->key == key) { return it->values.data(); break; } } } else return nullptr; } // IMPLEMENT ME: INSERT VALUE INTO A SEQUENCE IDENTIFIED BY GIVEN KEY void insert(int key, int value) { if(v.size() == 0) { //empty list v.push_back(key); node n; n.key = key; n.values.push_back(value); myList.push_back(n); } else if((find(v.begin(), v.end(), key)!=v.end())) { //if key exists already for(list<node>::iterator it = myList.begin(); it != myList.end(); it++) { if (it->key == key) { it->values.push_back(value); break; } } } else { //if theres no existing key v.push_back(key); node n; n.key = key; n.values.push_back(value); myList.push_back(n); } } private: vector<int> v; list<node> myList; }; // class key_value_sequences

我无法理解原因。我的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.位于 https格式

baseURL

请给我并提示!! 我只是一个新手,我猜测SWAPI只支持http协议。

1 个答案:

答案 0 :(得分:7)

似乎你是对的,SWAPI只支持http协议。

为了支持不安全的连接,请执行以下操作:

  1. 打开info.plist文件
  2. 将名为App Transport Security Settings的密钥添加为Dictionary(字典应为默认类型)
  3. 将名为Allow Arbitrary Loads的子项添加为Boolean(布尔值应为默认类型)。将其设置为YES
  4. 另见屏幕截图:

    enter image description here