1

My app is issuing ajax requests to a remote server. The same app works ok in IOS 12.4 but in IOS 14 the ajax requests are failing for CORS related errors.

I see the origin sent as null

I see that IOS 14 forces an OPTIONS (http server log)request when we are only submitting a POST via ajax. This OPTIONS request is not sent by IOS on IOS version 12.4 (again same app). Also works fine in Android.

Is there a simple solution to this ? I tried setting the CORS on server but I have not been successful.

I saw this post Cordova 10.0 Ajax not working in iOS 14 but working fine in Android

but did not offer a solution.

Error we see in javascript console

[Error] Preflight response is not successful
[Error] XMLHttpRequest cannot load https://<server>:<port>/<subdirectory>/page.jsp?d=x due to access control checks.
[Error] Failed to load resource: Preflight response is not successful (page.jsp, line 0)

Thanks

Esra
  • 11
  • 2

1 Answers1

1

Just spitballing... a couple of things that might be at play here:

  1. You might need to upgrade to the latest cordova-ios (6.1.1), unless that's a typo in your description.

  2. Maybe you're running into some of the tightened security enforced by the WKWebView in newer versions of cordova-ios. Try adding the following preferences to your config.xml file:

    <preference name="scheme" value="app" />
    <preference name="hostname" value="localhost" />
    

(Reference: https://cordova.apache.org/announcements/2020/06/01/cordova-ios-release-6.0.0.html)

eb1
  • 2,897
  • 3
  • 31
  • 42
  • Thanks for the feedback. It was not a typo. It is cordova-ios 5.1.1 . Same app works in IOS 12.4 . I am not sure why the request requires a preflight . Its a simple request based on https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests. To me it looks like a bug in IOS 14. – Esra Nov 12 '20 at 19:59