2017-04-19 69 views
0

enter image description hereiOS網絡錯誤,甚至應用程序傳輸安全關閉

你好,我正在與反應原生iOS應用程序。我使用外部服務器來檢查一些數據,所以我允許在Info.plist文件中的所有http請求。

但是正如您所看到的,在屏幕截圖的控制檯中,承諾拒絕 - 發生了網絡錯誤

Android中的相同代碼,效果很好。

我在iOS模擬器和真實設備上測試過,都失敗了。

你能幫助我什麼是問題。

謝謝。

http代碼部分就是這樣,這在Android模擬器中效果很好。

axios.get('http://suggest.hub.daum.net/suggest?q='+query+'&mod=json&code=utf_in_out&callback=suggestCallback&id=54') 
      .then((response) => { 
       ... 
      }); 

加...

這是完整的代碼。

findStock = (query, cb) => { 
     console.log('find stock ' + query); 
     if (query === '') { 
      console.log('set default sgs'); 
      this.setState({suggestions: []}) 
      return []; 
     } 

     else { 
      axios.get('http://suggest.hub.daum.net/suggest?q=' + query + '&mod=json&code=utf_in_out&callback=suggestCallback&id=54') 
       .then((response) => { 
        console.log(response); 
        var suggestions = (JSON.parse(response.data.substring(0, response.data.length - 2).replace('suggestCallback (', '')).items); 
        cb(suggestions); 
       }) 
       .catch((error) => { 
        console.log(error); 
        throw error; 
       }); 
     } 
    }; 


    render() { 

     var that = this; 
     const comp = (a, b) => a.toLowerCase().trim() === b.toLowerCase().trim(); 

     var _saveCondition = (stock, types, filters) => { 
      Keyboard.dismiss(); 
      this.props.onStartCreateCondition(stock, types, filters); 
     }; 

     return (
      <View style={{ flex: 1, justifyContent: 'flex-start', backgroundColor: '#3e63bc'}}> 
       <HeaderComponent showToPrevious={true}/> 

       <View style={{ padding: 30, zIndex: 10 }}> 
        <View style={{ marginBottom: 25 }}> 
         <Text style={{ color: '#fff', fontSize:15}}>알림 조건 추가</Text> 
        </View> 

        <View style={{ flexDirection: 'row', zIndex: 2, height: 45, alignItems: 'center' }}> 
         <View style={{ justifyContent: 'center', height: 100}}> 
          <Icon 
           name='search' 
           color='#fff' 
           size={25} 
          /> 
         </View> 
         <Autocomplete 
          style={{ marginLeft:0, paddingLeft:0, fontSize: 14, height:34, color: '#afc5da' }} 
          containerStyle={{ marginLeft: 10, flex: 1, height:40}} 
          inputContainerStyle={{ marginLeft:0, paddingLeft:0, borderWidth: 0, borderBottomWidth: 1, borderBottomColor: '#afc5da', }} 
          listContainerStyle={{ marginTop:-10, paddingTop:0 }} 
          listStyle={{ margin: 0, backgroundColor: '#afc5da' }} 
          data={this.state.suggestions.length === 1 && comp(this.state.query, this.state.suggestions[0]) ? ['aaaaa'] : this.state.suggestions} 
          defaultValue={this.state.query} 
          onChangeText={(text) => { 

          this.setState({ query: text}); 
          this.findStock(text, function(sgs) { 
          that.setState({suggestions : sgs}) 
          }); 

          }} 
          placeholder="종목명을 입력하세요." 
          placeholderTextColor={'#afc5da'} 
          renderItem={data => (
          <TouchableOpacity onPress={() => { 
          this.setState({ query: data }); 
          that.setState({ suggestions : []}) 
          Keyboard.dismiss(); 
          }}> 
           <Text>{data}</Text> 
          </TouchableOpacity> 
         )} 
         /> 

        </View> 
        .... 
+0

你能給網址的注入查詢後爲例? – CZ54

+0

在我看來,這個問題不在ATS。看[這裏](http://stackoverflow.com/questions/38842499/react-native-possible-unhandled-promise-rejection) –

+0

@ CZ54你可以把任何字符..像'samsung'。該網址在韓國股市中返回了關鍵字建議。 – Juntae

回答

0

問題是編輯Info.plist文件,允許specifc域,而不是所有的域後消失了。並且我聽說如果您嘗試在應用商店中上傳您的應用,那麼如果您允許所有http域,它將在iOS 10 +中被拒絕。

這裏是我的應用程序傳輸安全

<key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSExceptionDomains</key> 
      <dict> 
       <key>specificDomain.com</key> 
       <dict> 
        <key>NSIncludesSubdomains</key> 
        <true/> 
        <key>NSExceptionAllowsInsecureHTTPLoads</key> 
        <true/> 
        <key>NSExceptionRequiresForwardSecrecy</key> 
        <false/> 
       </dict> 
      </dict> 
     <key>NSAllowsLocalNetworking</key> 
     <true/> 
    </dict> 
相關問題