iOS -- ibeacon的相关知识

第一.ibeacon的扫描实现

    1.导入头文件,调用代理和定义属性
        
            #import <CoreLocation/CoreLocation.h>

            <CLLocationManagerDelegate>
            
            @property (strong, nonatomic) CLBeaconRegion *myBeaconRegion;
            @property (strong, nonatomic) CLLocationManager *locationManager;

    2.配置info.plist相关参数
4BFBDBDF-699D-4FEF-B008-D05AE9FA1C60.png
    3.初始化相关变量

         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.调用相关方法

        - (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion*)region
        {
            NSLog(@"开始。。。");
        //    [self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
        }
        
        -(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion*)region
        {
            NSLog(@"结束。。。");
        //    [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);
        }

第二.相关知识链接和demo实现

知识链接

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,037评论 25 709
  • @end 与之前一样,你需要初始化位置管理器并设置它们的 delegate 。 在 application:did...
    LiWeiJ阅读 6,579评论 0 0
  • 张炎做梦了。梦中的他站在初夏的家乡,背对一片布满草叶与三色兰的缓坡,对面的阳光亮得有些刺眼,让人有些看不清近处蒸腾...
    草蒙茸阅读 4,185评论 2 4
  • 最近,一段关于地铁男子辱骂两个女人的视频在网上传的沸沸扬扬,视频中一名少年男子与两名女孩在地铁车厢里发生口角,男子...
    木石之林阅读 3,803评论 3 3
  • 十年同学聚会,李小林刻意的收拾了一番。 站在穿衣镜前,整理好妻子小雅熨烫妥帖的衣服,看着已经出现眼角纹的越来越成熟...
    袁心颜阅读 3,047评论 3 1

友情链接更多精彩内容