didEnterRegion is not Called but didExitRegion is Called in objective C

心不动则不痛 提交于 2019-12-23 05:10:26

问题


Hi everyone in my app i'm finding the iBeacons here the didExitRegion Method i called when i exit from the Region but the didEnterRegion method is not called when i entering the region.i fixed the background Refresh,remote notifications,location request always in info.plist

here is my code

- (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{}

回答1:


Check didEnterRegion signature: you wrote locationManage not locationManager



来源:https://stackoverflow.com/questions/36576912/didenterregion-is-not-called-but-didexitregion-is-called-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!