Make sure Personal VPN entitlement is enabled for your application.
In your AppDelegate object initialize SDK:
// AppDelegate.swift or any other class to initialize SDK
CakeTube.instance().configure(CTConfig.create { (c) in
c.baseUrl = "BASE_URL"
c.carrierId = "CARRIER_ID"
c.vpnProfileName = "YOUR_APP_NAME" // will be shown in System Settings -> VPN
})
Make sure if you are logged in before connecting VPN, if not – sign in with any available method.
CakeTube.instance().login(with: CTAuthMethod.anonymous(), completion: { (user, e) in
// Do stuff
})
After you're logged in, you're good to go start VPN:
CakeTube.instance().startVPN { (location, e) in
// VPN is being started to server in country that is provided by `location` class
// Rely on notification center status notifications for exact VPN state
}
Handle VPN state notifications:
NotificationCenter.default.addObserver(forName: NSNotification.Name.CTVPNStatusDidChange, object: nil, queue: OperationQueue.main) { [unowned self] (notifictaion) in
if CakeTube.instance().vpnStatus == .connected {
// Do stuff
}
}
If you have to choose VPN server country before connecting, you can call availableServers and then startVpn with specific country.
// Get a list of countries
CakeTube.instance().availableServers { [weak self] (locations, e) in
// Do stuff
let someLocation = locations[0]
CakeTube.instance().setServer(someLocation)
// Next startVPN will use this location to connect
}