Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

ios - CORS error in Ionic 3

I am facing a very peculiar issue, when using Ionic 3 in iOS, I am trying to connect to a different domain [ddd.com], and since Ionic 3 uses WebKit, it changes the hostname to localhost:8080 in iOS.

This created a CORS issue, I was able to fix it by adding Allow-Control-Allow-Origin: http//localhost:8080 and Access-Control-Allow-Credentials: true.

Though this seems to work it had one issue, it never works the "first time" i.e when the app is downloaded and opened for the very first time. But it works when the app is killed and re-opened.

Any clue to un-wrap this tangly dangly mystery would be much appreciated.

  • Krishna Sagar
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ionic3 use WKWebview where it enforces security for Ajax request. In 2 ways it can be rectified.

First solution: Use UIWebview instead of WKWebView. But these solution costs the performance of the App.

Second Solution Instead of angular HTTP call, Use native HTTP call. Use this plugin for easy implementation.

https://github.com/sneas/ionic-native-http-connection-backend


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...