// ViewController.m#import "ViewController.h"#import "KontaktSDK.h"@interfaceViewController()<KTKLocationManagerDelegate>@property(strong,nonatomic)KTKLocationManager*lm;@end@implementationViewController-(void)viewDidLoad{[superviewDidLoad];_lm=[KTKLocationManagernew];_lm.delegate=self;if([KTKLocationManagercanMonitorBeacons]){KTKRegion*region=[KTKRegionalloc]init];region.uuid=@"AF41A130-E105-4F13-9483-316B7101B0A9";[_lmsetRegions:@[region]];]}}-(void)viewDidAppear:(BOOL)animated{[superviewDidAppear:animated];[_lmstartMonitoringBeacons];}-(void)viewDidDisappear:(BOOL)animated{[superviewDidDisappear:animated];[_lmstopMonitoringBeacons];}-(void)didReceiveMemoryWarning{[superdidReceiveMemoryWarning];}#pragma mark - KTKLocationManagerDelegate-(void)locationManager:(KTKLocationManager*)locationManagerdidChangeState:(KTKLocationManagerState)statewithError:(NSError*)error{if(state==KTKLocationManagerStateFailed){NSLog(@"Something went wrong with your Location Services settings. Check OS settings.");}}-(void)locationManager:(KTKLocationManager*)locationManagerdidEnterRegion:(KTKRegion*)region{NSLog(@"Enter region %@",region.uuid);}-(void)locationManager:(KTKLocationManager*)locationManagerdidExitRegion:(KTKRegion*)region{NSLog(@"Exit region %@",region.uuid);}-(void)locationManager:(KTKLocationManager*)locationManagerdidRangeBeacons:(NSArray*)beacons{NSLog(@"Ranged beacons count: %lu",[beaconscount]);}@end
// ViewController.swiftimportUIKitclassViewController:UIViewController,KTKLocationManagerDelegate{letlm:KTKLocationManager=KTKLocationManager()overridefuncviewDidLoad(){super.viewDidLoad()if(KTKLocationManager.canMonitorBeacons()){letregion:KTKRegion=KTKRegion()region.uuid="AF41A130-E105-4F13-9483-316B7101B0A9"lm.setRegions([region])self.lm.delegate=self}}overridefuncviewDidAppear(animated:Bool){super.viewDidAppear(animated)lm.startMonitoringBeacons()}overridefuncviewDidDisappear(animated:Bool){super.viewDidDisappear(animated)lm.stopMonitoringBeacons()}overridefuncdidReceiveMemoryWarning(){super.didReceiveMemoryWarning()}funclocationManager(locationManager:KTKLocationManager!,didChangeStatestate:KTKLocationManagerState,withErrorerror:NSError!){if(state==.Failed){println("Something went wrong with your Location Services settings. Check OS settings.")}}funclocationManager(locationManager:KTKLocationManager!,didEnterRegionregion:KTKRegion!){println("Enter region \(region.uuid)")}funclocationManager(locationManager:KTKLocationManager!,didExitRegionregion:KTKRegion!){println("Exit region \(region.uuid)")}funclocationManager(locationManager:KTKLocationManager!,didRangeBeaconsbeacons:[AnyObject]!){println("Ranged beacons count: \(beacons.count)")}}