0

enter image description here

Hello, I'm making iOS application with react-native. I'm using external server to check some data, so I allowed all of http request in Info.plist file.

But as you can see, in console of screen shot, Promise Rejection - Network Error occurred.

same code in Android, it works well.

I tested it in iOS simulator and real device, both failed.

Can you help me what is problem.

Thanks.

the http code part is like this, this works well in Android emulator.

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

plus...

this is full code.

 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>
                    ....
ton1
  • 7,238
  • 18
  • 71
  • 126
  • Can you give an exemple of url after injecting your query ? – CZ54 Apr 19 '17 at 07:34
  • it seems to me, that issue is not in ATS. look [here](http://stackoverflow.com/questions/38842499/react-native-possible-unhandled-promise-rejection) – Vladyslav Zavalykhatko Apr 19 '17 at 07:35
  • @CZ54 you can put any characters.. like `samsung`. that url returned keyword suggestions in Korean stock market. – ton1 Apr 19 '17 at 07:41
  • @VladHatko yep I added catch statement into it, but problem still left. – ton1 Apr 19 '17 at 07:42
  • I don't know why, if the syntax has a problem, why it works well in Android... – ton1 Apr 19 '17 at 07:43
  • The answer is not a JSON, so JSON.parse will always fail no ? – CZ54 Apr 19 '17 at 07:59
  • @CZ54 So I did `substring` and `replace` to make it JSON shape. I removed JSON.parse part of code and tried again but still got problem... Thank you for your concern... – ton1 Apr 19 '17 at 08:20
  • @CZ54 It maybe http problem. I switched http://.... to https://... google.com , the error was gone. – ton1 Apr 19 '17 at 08:26

1 Answers1

0

Problem was gone after editing Info.plist file that allow specifc domains rather than all domains. and I heard that if you trying upload your app in app store it will be rejected in iOS 10 + if you allow all http domains.

Here is my App Transport Security

<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>
ton1
  • 7,238
  • 18
  • 71
  • 126