sinusGob sinusGob - 3 years ago 175
iOS Question

Alamofire doesn't execute the URL

I have a server running in node, I tried using postman and it works just fine, but when I execute it from IOS client, it doesn't execute the URL, I checked my server it doesn't even called the API

Node server

router.post('/api/accounts/login', (req, res, next) => {
var user = new User():
user.name = req.body.name;
user.pass = req.body.password;
user.save((err) => {
res.json("Success");
});
});


Alamofire

let mainURL = "https://examplelogin.com"
let facebookLogin = "\(mainURL)/api/accounts/login"

func loginButtonTapped(_ name: String, _ pass: String) {

let parameters: [String: AnyObject] = [
"name": name as AnyObject,
"password": pass as AnyObject
]

Alamofire.request(facebookLogin, method: .post, parameters: parameters, encoding: JSONEncoding.default)
.responseJSON { response in
if let value = response.result.value {
let json = JSON(value)

// Do something


}
}

}


To be more specific, I hosted my node server on Heroku, I use namecheap to get the full domain name, but for somehow my ios client doesn't execute the API, do i need to add anything on the Info.plist?

Dix Dix
Answer Source

try this

1.add this code for show error.

else if let ERROR = response.result.error { 
   print(ERROR.localizedDescription)
}

2.Add this code in info.plist file.

<key>NSAppTransportSecurity</key>
<dict> 
  <key>NSAllowsArbitraryLoads</key> <true/> 
</dict> 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download