第一.ibeacon的掃描實(shí)現(xiàn)
1.導(dǎo)入頭文件,調(diào)用代理和定義屬性
#import <CoreLocation/CoreLocation.h>
<CLLocationManagerDelegate>
@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion;
@property (strong, nonatomic) CLLocationManager *locationManager;
2.配置info.plist相關(guān)參數(shù)
4BFBDBDF-699D-4FEF-B008-D05AE9FA1C60.png
3.初始化相關(guān)變量
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
//傳入自己使用的ibeacon的UUID
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"e2c56db5-dffb-48d2-b060-d0f5a71096e0"];
self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
identifier:@"com.appcoda.testregion"];
[self.myBeaconRegion peripheralDataWithMeasuredPower:@-30];
[_locationManager requestAlwaysAuthorization];
[self.locationManager startMonitoringForRegion:self.myBeaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
4.調(diào)用相關(guān)方法
- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion*)region
{
NSLog(@"開始。误堡。。");
// [self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
}
-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion*)region
{
NSLog(@"結(jié)束毯辅。埂伦。煞额。");
// [self.locationManager stopRangingBeaconsInRegion:self.myBeaconRegion];
}
-(void)locationManager:(CLLocationManager*)manager
didRangeBeacons:(NSArray*)beacons
inRegion:(CLBeaconRegion*)region
{
// CLBeacon *foundBeacon = [beacons firstObject];
NSLog(@"-----------beacons: %@",beacons);
// NSLog(@"----------region: %@",region);
// NSLog(@"---------%@",manager);
}
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(@"Failed monitoring region: %@", error);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Location manager failed: %@", error);
}
第二.相關(guān)知識鏈接和demo實(shí)現(xiàn)