【问题标题】:Cordova HttpClient calls fails in IOS device but works in AndroidsCordova HttpClient 调用在 IOS 设备中失败,但在 Android 中有效
【发布时间】:2018-10-29 19:26:06
【问题描述】:

我知道HTTPS request fails only on iOS, Ionic 2 之前有人问过这个问题,但这些答案对我不起作用。

我已经在 ios xcode10 项目的 [myproject]-info.plist 文件中进行了以下设置

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

我的项目中没有安装 wkwebview 插件here,而是在我的项目中安装了 ionic-webview-plug。

端点是托管在 Windows 服务器中的 MVC 控制器操作方法。我无法像在 Android 测试中那样使用 chrome://inspect 从 Windows 调试 IOS 应用程序。虽然 App 能够访问图片等其他静态链接,但此 Web 服务调用失败。

下面的 Angular 代码是如何使用 HttpClient 进行 Web 服务调用的

var oDat = {
uuid: uuid
};
let headers = new HttpHeaders();
headers = headers.set(‘Content-Type’, ‘application/json; charset=utf-8’);
return this.http.post(this.apiUrl23, JSON.stringify(oDat), {headers: headers}).pipe(
map(this.extractData),
catchError(this.handleError)
);

以下是从页面触发的此类订阅者代码

  this.horoService.getPlan(this.device.uuid)
           .subscribe(res => {
                this.info2 = '';
                let pln: Plan = { uuid: res['uuid'], name: res['name'], credits: res['credits'], dobs: res['dobs'] };
                this.plan = pln;
                if(res['name'] == 'xxx.xxx.xxx.xxx'){
                    this.showSU = true;
                    this.showCR = false;
                    this.showASU = false;
                } else if(Number(res['credits']) == 0) {
                    this.showSU = false;
                    this.showCR = true;
                    this.showASU = false;
                } else {
                    this.showSU = true;
                    this.showCR = false;
                    this.showASU = true;
                }
            }, (err) => {
                    this.showSU = false;
                    this.showCR = false;
                    this.showASU = false;
                this.info2 = JSON.stringify(err);
            });    

以下是我项目中使用的 Cordova 版本

Ionic:
   ionic (Ionic CLI)  : 4.2.1 (C:\Users\Hamsini\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 6.3.0, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 1.2.1, (and 12 other plugins)

在 xCode10 上构建并在 ipad 版本 9.3.5 上测试

你猜到了吗?

UPDATE-30/10 当我使用 ionic serve 运行时,我可以看到 HTTPResponse 正确返回,但是在 .subscribe (err) 处理程序中它显示 Unknown URL, Unknown error

【问题讨论】:

  • 你遇到了什么错误?
  • 实际上通信没有问题,因为我可以看到 HTTPResponse 在从 ionic serve 测试时返回,而 (err) 显示为未知 URL,未知错误

标签: ios cordova


【解决方案1】:

我正在回答我自己的问题,因为这可能会对某人有所帮助。

downgrading to UIWebView 似乎已解决后,WKWebView 的问题似乎已解决

在 Cordova 解决问题之前,现在需要执行以下步骤

这个post 非常详细地介绍了 xCode10 和 Cordova 的兼容性问题,自从推出以来已经有一段时间了,Cordova 家伙还没有提出解决方案,解决方法是在构建过程中忽略新架构,部署过程对于 iOS 来说有点复杂,因为它更多地依赖 XCode 一个 MAC 平台,所以在你使用下面的命令行构建之后

ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"

您还必须确保在 xCode 构建设置中选择 "Legacy Build System",如图所示 herehere

但是由于这次降级可能会导致其他副作用,例如在应用程序中点击 SVG 图像的某些部分无法正常工作,之前在 Android 设备上可以正常工作,对此偶数侦听器动态附加不确定如果这是由于降级导致的

【讨论】:

    猜你喜欢
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多