iOS v12 Https requests errors

2019-02-10 02:30发布

I noticed that https requests made from my Ionic Angular app on iOS v12 are failing respectively never reach my backend.

I could confirm that my app is productive and the fact that this error only occurs on iOS >= v12

When I debug in Xcode 10 beta I get the following error

{“headers”:{“normalizedNames”:{},“lazyUpdate”:null,“headers”:{}},“status”:0,“statusText”:“Unknown Error”,“url”:null,“ok”:false,“name”:“HttpErrorResponse”,“message”:“Http failure response for (unknown url): 0 Unknown Error”,“error”:{“isTrusted”:true}}

My Node / Express.js backend set the following headers

var allowedOrigins = ["https://example.com", "http://ionic.local", "http://localhost:8080"];

 var origin = req.headers.origin;
 if(allowedOrigins.indexOf(origin) > -1){
        res.setHeader('Access-Control-Allow-Origin', origin);
 } else {
        res.setHeader("Access-Control-Allow-Origin", "https://example.com");
    }

 res.header("Access-Control-Allow-Credentials", "true") 
 res.header("Access-Control-Allow-Headers", "Origin, Authorization, Content-Type, Content-Range, Content-Disposition, Content-Description, X-Requested-With, X-ACCESS_TOKEN");
 res.header("Access-Control-Allow-Methods", "GET,PUT,POST");

Anyone is facing the same problem? What did you change in your code to fix the problem for iOS v12?

P.S.: I have opened an issue by Apple

Also here the linked subject on the Ionic forum: https://forum.ionicframework.com/t/ios-12-beta-preflight-requests-fail

And just in case opened an issue on the WkWebView plugin: https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/112

UPDATE

I'm not sure but it looks like that I only face issue while querying POST requests respectively that I don't face it while doing GET requests...could you confirm that too?

UPDATE 2

In the following discussion/issue, https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/112, we are also betting on a bug in the iOS version itself. Let see if it will be corrected with the next beta version

UPDATE 3

Xcode 10 beta 2 respectively iOS 12 beta 2 released Tuesday 19th June 2018 solved my problem

3条回答
啃猪蹄的小仙女
2楼-- · 2019-02-10 03:18

I'm feeling very confident that this is just a beta 1 bug with no confirmed work around. I never found an opportunity to get this verified in person while at WWDC, but it seems to be very confirmed by multiple sources including this bug on open radar. I'm going to file an additional bug with Apple directly and will update my answer with any responses.

Update: I've tested multiple devices on iOS 12 beta 2 and the issue seems to be resolved. No update on the bug filed with Apple, but I'm going to assume that it was addressed in the latest update.

Update 2: Apple has finally closed my bug as fixed.

查看更多
Melony?
3楼-- · 2019-02-10 03:19

The problem was an internal problem of iOS 12 beta 1

Xcode 10 beta 2 respectively iOS 12 beta 2 released Tuesday 19th June 2018 solved my problem

查看更多
劳资没心,怎么记你
4楼-- · 2019-02-10 03:19

Test is issue, On iOS 12, below two ways will not run into this issue

  1. request with HTTP
  2. post request with form-data, not with json. if you post with JSON, will trigger option request, but webkit not post this request, so cros domain failed
查看更多
登录 后发表回答