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.