2016-06-14 16:01:19 -07:00
iOS + ZeroTier SDK
====
Welcome!
Imagine a flat, encrypted, no-configuration LAN for all of the instances of your iOS app.
2016-07-18 17:34:18 -07:00
This short tutorial will show you how to enable ZeroTier functionality for your iOS app with little to no code modification. Check out our [ZeroTier SDK ](https://www.zerotier.com/blog ) page for more info on how the integration works.
2016-06-14 16:01:19 -07:00
2016-07-14 08:40:40 -07:00
***
**Step 1: Build iOS framework**
2016-06-14 16:01:19 -07:00
2016-07-14 08:40:40 -07:00
- `make ios_app_framework`
- This will output to `build/ios_app_framework/Release-iphoneos/ZeroTierSDK_iOS.framework`
2016-06-14 16:01:19 -07:00
2016-07-14 08:40:40 -07:00
**Step 2: Integrate SDK into project**
2016-06-14 16:01:19 -07:00
2016-07-14 08:40:40 -07:00
- Add the resultant framework package to your project
2016-08-25 17:08:48 -07:00
- Add `src` directory to *Build Settings -> Header Search Paths*
2016-07-14 08:40:40 -07:00
- Add `build/ios_app_framework/Release-iphoneos/` to *Build Settings -> Framework Search Paths*
- Add `ZeroTierSDK.frameworkiOS` to *General->Embedded Binaries*
2016-11-15 16:18:26 -08:00
- Add `src/wrappers/swift/ZTSDK.swift` , `src/wrappers/swift/XcodeWrapper.cpp` and `src/wrappers/swift/XcodeWrapper.hpp` to your project:
- Set `src/wrappers/swift/Apple-Bridging-Header.h` as your bridging-header in *Build Settings -> Objective-C Bridging-header*
2016-06-14 16:01:19 -07:00
2016-07-14 08:40:40 -07:00
**Step 3: Start the ZeroTier service**
2016-06-14 16:01:19 -07:00
2016-09-09 12:17:42 -07:00
Start the service:
2016-09-09 12:02:27 -07:00
2016-06-14 16:01:19 -07:00
```
2016-09-09 12:02:27 -07:00
zt.start_service(nil);
zt.join_network(nwid);
2016-06-14 16:01:19 -07:00
```
2016-09-09 12:02:27 -07:00
Listen for incoming connections:
2016-06-14 16:01:19 -07:00
```
2016-09-09 12:02:27 -07:00
let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0)
let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort))
let bind_err = zt.bind(sock, ztaddr)
zt_listen(sock, 1);
2016-09-09 12:17:42 -07:00
let accepted_sock: Int32 = zt.accept(sock, ztaddr)
2016-09-09 12:02:27 -07:00
```
Or, establish a connection:
```
let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0)
let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort))
2016-09-09 12:17:42 -07:00
let connect_err: Int32 = zt.connect(sock, ztaddr)
2016-06-14 16:01:19 -07:00
```
2016-09-09 12:17:42 -07:00
**Alternative APIs**
2016-06-14 16:01:19 -07:00
2016-09-09 12:17:42 -07:00
CLick [here ](../../../../docs/api_discussion.md ) to learn more about alternative APIs such as the Intercept and SOCKS5 Proxy.