【发布时间】:2015-03-27 17:41:32
【问题描述】:
我不知道我是否错过了我的信标设置。我尝试了一切,但代码对我不起作用。我的信标是 kontakt.io。我尝试了 sdk 和示例代码,但仍然无法正常工作。 这是我的代码:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "KontaktSDK.h"
@interface ViewController : UIViewController <KTKLocationManagerDelegate,KTKActionManagerDelegate,KTKBluetoothManagerDelegate>
@property (strong,nonatomic) KTKLocationManager * ktkLocationManger;
@property (strong,nonatomic) CLLocationManager * locationManager;
@property (strong,nonatomic) KTKRegion * ktkRegion;
@property (strong,nonatomic) KTKActionManager * actionManager;
@property (strong,nonatomic) KTKBluetoothManager * bluetoothManager;
@property (strong,nonatomic) KTKBeaconManager * beaconManager;
@end
还有我的 viewcontroller.h
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *beaconLabel;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.ktkLocationManger = [[KTKLocationManager alloc] init];
self.ktkLocationManger.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
if ([KTKLocationManager canMonitorBeacons])
{
KTKRegion *region =[[KTKRegion alloc] init];
region.uuid = @"A77A1B68-49A7-4DBF-914C-760D07FBB87B"; // kontakt.io proximity UUID
[self.ktkLocationManger setRegions:@[region]];
[self.ktkLocationManger startMonitoringBeacons];
self.bluetoothManager = [[KTKBluetoothManager alloc] init];
self.bluetoothManager.delegate = self;
self.beaconManager = [[KTKBeaconManager alloc] init];
self.beaconManager.delegate = self;
[self.beaconManager startFindingDevices];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self.ktkLocationManger startMonitoringBeacons];
}
- (void)locationManager:(KTKLocationManager *)locationManager didChangeState:(KTKLocationManagerState)state withError:(NSError *)error
{
if (state == KTKLocationManagerStateFailed)
{
NSLog(@"Something went wrong with your Location Services settings. Check OS settings.");
}
}
- (void)locationManager:(KTKLocationManager *)locationManager didEnterRegion:(KTKRegion *)region
{
NSLog(@"Enter region %@", region.uuid);
self.beaconLabel.text=@"enter";
}
- (void)locationManager:(KTKLocationManager *)locationManager didExitRegion:(KTKRegion *)region
{
NSLog(@"Exit region %@", region.uuid);
self.beaconLabel.text=@"exit";
}
- (void)locationManager:(KTKLocationManager *)locationManager didRangeBeacons:(NSArray *)beacons
{
NSLog(@"Ranged beacons count: %lu", [beacons count]);
self.beaconLabel.text=@"Range";
}
我尝试了一切只是为了使用 didRangeBeacons: 但多次失败。 有什么我需要设置的,或者我只是错过了代码。希望得到您的建议或帮助。提前谢谢
【问题讨论】:
标签: ios objective-c ibeacon