didEnterRegion信标管理器方法返回一个nil major和minor的区域

时间:2015-06-30 15:19:42

标签: ios

在appDelegate中,我有一个信标管理器和3个信标区域,每个区域都使用相同的UUID进行初始化,但具有不同的主要和未成年人。我在每个信标区域调用了startMonitoringForRegion方法。 问题是,有时在didEnterRegion委托方法中,即使我所有的区域都有未成年人和专业,该区域也有null和minor。我还为每个区域设置了不同的标识符。我必须清楚自己,超过50%的我不会在didEnterRegion中获得nil major和minor,但有时它们是nil.Also我使用estimote SDK。

有人可以帮帮我吗?非常感谢你。

以下是我的代码的一小部分:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/*
 * Persmission to show Local Notification.
 */
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}

/*
 * BeaconManager setup.
 */

self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;

self.firstBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"] major:34587 minor:56726 identifier:@"firstRegionIdentifier"];
self.secondBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"] major:23423 minor:45232 identifier:@"secondRegionIdentifier"];
self.thirdBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"] major:20106 minor:14567 identifier:@"thirdRegionIdentifier"];

self.firstBeaconRegion.notifyOnEntry = YES;
self.secondBeaconRegion.notifyOnEntry = YES;
self.thirdBeaconRegion.notifyOnEntry = YES;

[self.beaconManager startMonitoringForRegion:self.firstBeaconRegion];
[self.beaconManager startMonitoringForRegion:self.secondBeaconRegion];
[self.beaconManager startMonitoringForRegion:self.thirdBeaconRegion];

return YES;
}

- (void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region
{

if (region.major != nil) {

    [[RTRequestManager sharedInstance] requestBeaconWithUUID:region.proximityUUID major:region.major withCompletionBlock:^(NSArray *objects, NSError *error) {

        UILocalNotification *notification = [UILocalNotification new];
        notification.alertBody = [[objects firstObject] objectForKey:@"beaconLocationDetails"];
        notification.soundName = UILocalNotificationDefaultSoundName;

        NSString *beaconUUID =[NSString stringWithFormat:@"%@%@",[region.proximityUUID UUIDString],region.major];
        RTBeaconViewController *beaconVC = [[RTBeaconViewController alloc] initWithBeacon:beaconUUID];
        [_navController.topViewController presentViewController:beaconVC animated:YES completion:nil];

        [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
    }];

}
}

1 个答案:

答案 0 :(得分:1)

试试这个: -

         NSSet *set=[self.beaconManager1 monitoredRegions];                
               if ([set count]<3) 
{
[self.beaconManager startMonitoringForRegion: [[CLBeaconRegion alloc]                                                               initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID major:anyvalue minor:anyyour value                                                                       identifier:@"your identifier"]]; 
}

每次进入,退出甚至发生这些didlaunchwithoption将被称为你正在一次又一次地监视同一地区,即使这些地区将在下次调用startmonitoring时取代。但是我看到了一些与此相关的问题,因此,您必须检查它是否已经在监视,因为您只想监视这些区域一次。重新启动设备后尝试