なんとかするから、なんとかなる

エンジニア関係のことを書きます

How to connect to localhost on Mac from iPhone

Introduction

This article shows how to connect to localhost on Mac from iPhone and some tips.

Conditions

How to connect it

  1. Set up the localhost server on a mac
  2. Confirm the access to the "localhost:{PortNumber}" by safari or something.
  3. Check the mac's domain name from [Preference] - [sharing] ({YOUR_PC_NAME}.local) f:id:hopita:20180930154815p:plain
  4. Access the domain({YOUR_PC_NAME}.local) from iPhone by safari or something.

Finished!

Tips1

If the localhost uses the port number 80 or some another famous ports, the inbound request will be refused by mac native firewall.

To solve the problem, turn off the native firewall from [Preference] - [Security&Privacy].

But, as you know, it's not recommended.

Tips2

If you would like to connect the mac as API Server from iOS app, you need to turn off the ATS(App Transport Security) on the Xcode.

But, if you can access the server from https connect, it's not a problem.