This guide aims to simplify the process of integrating WireGuard into your iOS application. I've tried to make this complex procedure easy. This project contains only integration, I will add connection part soon.
Start by creating a new project in Xcode if you haven't already done so.
- Add a new target to your project by selecting File > New > Target....
- Choose the Network Extension target type and click Next.
- Name your Network Extension, e.g.,
network-extension
, and then click Finish. - When prompted to activate the scheme for the network extension, select Cancel.
-
Add another new target by selecting File > New > Target... again. We are using this external build system for building wireguard.
-
This time, select External Build System.
-
Name this target
WireguardGoBridge
. -
In the Build Tool field, enter
$(PROJECT_DIR)/script/build_wireguard_go_bridge.sh
.- This script is responsible for building the WireGuard. You can find the script at
script/build_wireguard_go_bridge.sh
. Add script to your project. - Modify the Go path in the script at line 38 as necessary, according to your setup. Refer to this Stack Overflow answer for guidance.
- This script is responsible for building the WireGuard. You can find the script at
- To your project, add the WireGuardKit dependency by navigating to Project > Package Dependencies, then click the + button.
- Enter the URL
https://git.zx2c4.com/wireguard-apple
and select the exact version1.0.15-26
. - When prompted, select the
network-extension
target for the package.
-
For your Network Extension (NE) target:
- Go to Build Phases > Target Dependencies and add
WireguardGoBridge
as a dependency. - Under Build Phases > Link Binary with Libraries, ensure
WireguardKit
andNetworkExtension.framework
are available.
- Go to Build Phases > Target Dependencies and add
-
Ensure
WireguardKit
targets thenetwork-extension
in its build phases.
In your Network Extension target, add TunnelConfiguration+wgQuickConfig
and String+ArrayConversion
extensions. These will help in configuring the tunnel and handling array conversions, respectively.
Taken help from:
Feel free to open any issue or contact me if you face any issue.
- Email: [email protected]
I hope this guide facilitates a smoother integration process for you. Feedback and queries are always welcome.