class ViewController: UIViewController, CLLocationManagerDelegate, CBCentralManagerDelegate {
private let locationManager = CLLocationManager()
var centralManager: CBCentralManager?
let nodle = Nodle.sharedInstance
override func viewDidLoad() {
// Do any additional setup after loading the view.
// set manager for permissions
locationManager.delegate = self
// check status for location permission
switch CLLocationManager.authorizationStatus() {
case .authorizedWhenInUse, .authorizedAlways:
// request always auth if you would use it in the background
locationManager.requestAlwaysAuthorization()
// ask for bluetooth permissions
centralManager = CBCentralManager(delegate: self, queue: nil)
// ask for permissions if background otherwise use whenInUse
locationManager.requestAlwaysAuthorization()
print("Location permission denied")
nodle.start(devKey: "ss58:5FUfDdHhtn5Bzgte69zr1NyNRS7zFqy7CnjVcRUUpWpXz3Cv", tags: "","")
func centralManagerDidUpdateState(_ central: CBCentralManager) {
// start Nodle after Bluetooth permissions have been granted
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedWhenInUse || status == .authorizedAlways {
print("Location permission have been granted")
// ask for ble permissions
centralManager = CBCentralManager(delegate: self, queue: nil)