This guide aims to simplify the process of integrating WireGuard into your iOS application. I've tried to make this complex procedure easy.
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-appleand select the exact version1.0.15-26. - When prompted, select the
network-extensiontarget for the package.
-
For your Network Extension (NE) target:
- Go to Build Phases > Target Dependencies and add
WireguardGoBridgeas a dependency. - Under Build Phases > Link Binary with Libraries, ensure
WireguardKitandNetworkExtension.frameworkare available.
- Go to Build Phases > Target Dependencies and add
-
Ensure
WireguardKittargets thenetwork-extensionin 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.
Dont forget to change identifier here Also edit the wireguard config here
Also please note you will need real device for testing, Network extensions don't work on simulators.
- To your project, add the WireGuardKit dependency by navigating to Project > Package Dependencies, then click the + button.
- Enter the URL
https://github.com/ut360e/wireguard-apple.gitand add. - When prompted, select the
network-extensiontarget for the package.
-
In the Project Navigator, go to the NetworkExtension target → General → Frameworks & libraries.
-
Add libwg-go.a (included in the repository).
If you find this project helpful, consider supporting me:
Thank you for your support! 🙏
Taken help from:
Feel free to open any issue or contact me if you face any issues.
| Platform | Link |
|---|---|
| shahzainali93@gmail.com | |
| LinkedIn Profile | |
| StackOverflow | StackOverflow Profile |
I hope this guide facilitates a smoother integration process for you. Feedback and queries are always welcome.