Capacitor hostname config does not work for Ios

Hello, here is my capacitor.config.ts:

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'my.app.id',
  appName: 'My App Name',
  webDir: 'www',
  server: {
    hostname: "my.backend.com",
    androidScheme: "https"
  }
};

export default config;

I need the hostname config for my backend to allow cors, it works great for Android, I’m able to access my backend api, but it does not work for ios.

Why is that?

It is because http and https are not allowed in iOS as they are reserved schemas (reference). That is why Capacitor defaults to capacitor:// for iOS.

Why don’t you just allow the following Capacitor default origins in your backend?

  • capacitor://localhost - iOS
  • http://localhost - Android

I don’t have control over the backend… is there any other way to change ios hostname?

I think the only way around it is is to use the capacitor-community/http plugin. It uses the native HTTP APIs so requests aren’t considered CORS.

I see, the problem is that I use Apollo to query against a graphql api, so I guess I’m gonna have to drop it and use this plugin.

capacitor-coomunity/http - is working on android but IOS it failed. App is crashing on using Http.request.

I’m currently using Capacitor version 4.7.3.

Did i miss any configuration specific to IOS?

Capacitor now has a first party plugin here - Capacitor Http Plugin API | Capacitor Documentation. capacitor-community/http has been archived in lieu of that.

that probably was a capacitor 4.7.3 bug, try updating to 4.8.0

Was anyone able to get this working with the suggested plugin?

Thanks