首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未调用didEnterRegion,但在目标C中调用了didExitRegion

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

Stack Overflow用户
提问于 2016-04-12 22:54:07
回答 1查看 536关注 0票数 0

大家好,在我的应用程序中,我在这里找到了iBeacons退出区域时调用的didExitRegion方法,但进入区域时未调用didEnterRegion方法。我修复了后台刷新、远程通知、位置请求始终在info.plist中的问题

以下是我的代码

代码语言:javascript
复制
- (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{}
EN

回答 1

Stack Overflow用户

发布于 2016-07-28 22:05:15

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36576912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档