简体   繁体   中英

Ionic Capacitor - using Cordova plugins

I am attempting to use @ionic-native/http on iOS and Web with no success. App starts on both platforms, but the plugin does not work.

Dependencies

  • capacitor: "^1.0.0-beta.19"
  • @ionic/angular: "^4.1.0"
  • @angular: "^7.2.2"
  • @ionic-native: "^5.0.0"
  • @ionic/angular-toolkit: "~1.4.0"

I hope that covers the most important ones.

Steps to reproduce

App

  1. ionic start myApp tabs
  2. npm install --save @capacitor/cli @capacitor/core
  3. npm run build --prod
  4. npx cap init <name> <id>
  5. npx cap add ios
  6. npx cap copy
  7. npx cap open ios
    • general -> signing -> team

Plugin

  1. npm install cordova-plugin-advanced-http
  2. npm install @ionic-native/http
  3. npx cap sync
  4. Use it as shown in here

According to the documentation (which I might have misunderstood) that should be it.

Issues

When attempting to call an API:

Web

Native: tried calling HTTP.get, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

I know I don't use Cordova per se but shouldn't it be covered by npx cap sync ?

iOS

[error] - ERROR {"line":38,"column":38,"sourceURL":"capacitor://localhost/tab2-tab2-module.js"}

I was lucky to finally find some more information.

iOS

I am not really sure why, but this additional plugin helped https://github.com/sneas/ionic-native-http-connection-backend . Requests can be made through HttpClient and they use Cordova plugin so that they bypass proxy.

Web

Capacitor won't work on the browser according to https://github.com/ionic-team/capacitor/issues/767#issuecomment-415481452

So my assumption that it will was wrong. Previously mentioned plugin will delegate requests through HttpClient so it is nice workaround for the browser, although won't fix CORS issue.

CORS issue at this point can be handled by a proxy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM