在目标C中未调用didEnterRegion但已调用didExitRegion [英] didEnterRegion is not Called but didExitRegion is Called in objective C
本文介绍了在目标C中未调用didEnterRegion但已调用didExitRegion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中的大家好,我在这里找到iBeacons,当我从区域退出时我调用了didExitRegion方法,但是当我进入区域时未调用didEnterRegion方法。我修复了后台刷新,远程通知,定位请求始终在info.plist
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
这是我的代码
- (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{}
推荐答案
检查didEnterRegion签名:您写的是locationManage而不是locationManager
Check didEnterRegion signature: you wrote locationManage not locationManager
这篇关于在目标C中未调用didEnterRegion但已调用didExitRegion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文