未调用 didEnterRegion 但在目标 C 中调用了 didExitRegion

Posted

技术标签:

【中文标题】未调用 didEnterRegion 但在目标 C 中调用了 didExitRegion【英文标题】:didEnterRegion is not Called but didExitRegion is Called in objective C 【发布时间】:2016-04-12 14:54:07 【问题描述】:

嗨,我的应用程序中的每个人,我在这里找到 iBeacons,当我退出该区域时我调用了 didExitRegion 方法,但当我进入该区域时没有调用 didEnterRegion 方法。我修复了后台刷新、远程通知、位置请求总是在 info.plist 中

这是我的代码

- (void)viewDidLoad

    [super viewDidLoad];
    locManager=[[CLLocationManager alloc] init];
    locManager.delegate=self;

    [self initRegion];
    if([locManager respondsToSelector:@selector(requestAlwaysAuthorization)])
    
        [locManager requestAlwaysAuthorization];
    
//    clBeconRegion.notifyOnEntry=YES;
    clBeconRegion.notifyEntryStateOnDisplay=YES;


-(void)initRegion

    NSUUID *uuid=[[NSUUID alloc]initWithUUIDString:UUID];
    clBeconRegion=[[CLBeaconRegion alloc]initWithProximityUUID:uuid identifier:@"BeaconExample"];

//    clBeconRegion=[[CLBeaconRegion alloc]initWithProximityUUID:uuid major:8983 minor:738
//                                                    identifier:@"aB"];
    //    clBeconRegion=[[CLBeaconRegion alloc]initWithProximityUUID:uuid major:8983 minor:728
    //                                                    identifier:@"bB"];
    clBeconRegion.notifyOnEntry=YES;
//    clBeconRegion.notifyOnExit=YES;
    clBeconRegion.notifyEntryStateOnDisplay=YES;

    [locManager startMonitoringForRegion:clBeconRegion];

-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
  NSLog(@"didStartMonitoringFor Region");

//    [locManager startRangingBeaconsInRegion:clBeconRegion];
    [locManager requestStateForRegion:clBeconRegion];


-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region

    switch (state) 
        case CLRegionStateInside:
            [locManager startRangingBeaconsInRegion:clBeconRegion];
                        NSLog(@"Region Inside");
            break;
        case CLRegionStateOutside:
//            [locManager stopRangingBeaconsInRegion:clBeconRegion];
            NSLog(@"Region OutSide %ld",(long)state);
        case CLRegionStateUnknown:

        default:
            // stop ranging beacons, etc
            NSLog(@"Region unknown %ld",(long)state);
    

-(void)locationManage:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
    NSLog(@"Entered Region");
    [locManager startRangingBeaconsInRegion:clBeconRegion];

    CLBeaconRegion *reg=(CLBeaconRegion *)region;
    [disObj login:[NSString stringWithFormat:@"%@", reg.major] :[NSString stringWithFormat:@"%@", reg.minor]];
    NSString *enterRegion=[NSString stringWithFormat:@"You ENTERED a Region %@",reg.minor];
    [self sendLocalNotificationWithMessage1:enterRegion];

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region

       CLBeaconRegion *reg=(CLBeaconRegion *)region;
        NSString *exit=[NSString stringWithFormat:@"You Exit a Region %@",reg.minor];
    [self sendLocalNotificationWithMessage1:exit];
    NSLog(@"Exit Region");
    [locManager stopRangingBeaconsInRegion:clBeconRegion];

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region

【问题讨论】:

澄清一下,您是说您收到多次电话到didExitRegion(如果您再次打开和关闭信标)但从来没有任何电话到didEnterRegion 是的,一旦我退出一个区域,我就会多次调用 didExitRegion 但没有调用 didEnterRegion 【参考方案1】:

检查 didEnterRegion 签名:你写的是 locationManage 而不是 locationManager

【讨论】:

以上是关于未调用 didEnterRegion 但在目标 C 中调用了 didExitRegion的主要内容,如果未能解决你的问题,请参考以下文章

AltBeacon:当 BeaconConsumer 从 DidEnterRegion BootstrapNotifier 回调绑定时,未调用 onBeaconServiceConnect

didEnterRegion 以更大的半径调用(iOS)

iBeacon:didEnterRegion 永远不会被调用

CoreLocation startMonitoringRegion 未触发 didenterregion /didexitregion 代表

仅在调用 requestAlwaysAuthorization 时才调用 DidEnterRegion。信标

目标 C:UITableView:cellForRowAtIndexPath 在 iPhone 中被调用但在 iPad 中失败