Home Cannot reach server on iOS device but simulator works
Reply: 0

Cannot reach server on iOS device but simulator works

TPWang
1#
TPWang Published in 2018-02-14 08:15:58Z

I have my server written in Nodejs and express, last steps are like this:

server = app.listen(3000, function() { 
    console.log("Server listening on port 3000...\n");
});

I have my swift code like this (with my actual IP address):

Alamofire.request("http://123.123.123.123:3000", method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil)
        .validate(statusCode: 200..<300)
        .validate(contentType: ["application/json"])
        .response(completionHandler: completionHandler)

This will get me a response on the simulator, also works with browser (from another computer). But on my actual iPhone this would always time out and never give any response. I have

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

in my info.plist, I am not sure what I'm missing here.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319724 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO