VirtualProdigy
VirtualProdigy

Reputation: 1687

Ionic 2 iOS cors

I'm running into an issue with CORS in ionic 2. When I hit my login endpoint I get the following CORS error from the iOS build on a phone

[Error] Failed to load resource: Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin.

I'm not seeing this issue from the Android version of the application. Is there a setting or something that can be enabled within the Ionic app to fix the CORS issue?

Thanks in advance

Upvotes: 0

Views: 1055

Answers (4)

sijo vijayan
sijo vijayan

Reputation: 1710

Workaround only - Not a perfect solution


I was running with the same problem, My ionic 3 app with ASP.net backend was working just fine, it was not working with IOS ( Iphone x - IoS 11 simulator ).

Finally i got a solution

Solution

I changed the web view option of my ionic app.

First, open config.xml and add the following properties

<feature name="CDVWKWebViewEngine"> <param name="ios-package" value="CDVWKWebViewEngine" /> </feature> <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />

Then remove all plugins and platforms then run or build your app

That's it

Detailed steps given in this url

Upvotes: 1

At work we had this same error, only occurred in the iPhone, and after much research we discovered that this problem is referring to the server (API), not to the mobile application.

Our API is an ASP.NET application and is exposed through IIS. I do not know if your environment is the same, but basically what solved our problem was:

On the server, in IIS, in the application pool of our application we changed the Managed Pipeline Version property from Classic to Integrated, and the problem was solved.

Upvotes: 0

EHorodyski
EHorodyski

Reputation: 794

I'm hitting this issue as well. The servers are NOT locally hosted, but they are not CORS enabled either. The issue is that the HTTP requests are setting the origin to localhost, when it should be file://.

Anyone know how to avoid this?

Upvotes: -1

Alitlili
Alitlili

Reputation: 66

You have to set proxies in ionic.config.js like this :

{
  "name": "*******",
  "app_id": "******",
  "v2": true,
  "typescript": true,
  "proxies": [
    {
      "path": "/api",
      "proxyUrl": "http://localhost:8080"
    }
  ]
}

Here is a sample project provided by Ionic with proxy setup and small server returning static data. https://github.com/mhartington/V2Proxy

Upvotes: 1

Related Questions