1
votes

In appDelegate I have one beacon manager and 3 beacon regions each initialised with same UUID but with different majors and minors.I called the startMonitoringForRegion method on each of the beacon regions. The problem is that sometimes in didEnterRegion delegate method, the region has null major and minor even if I all my regions have minors and majors.I also set different identifiers to each region.I have to make myself clear, in more than 50% of times I don't get nil major and minor in didEnterRegion, but sometimes they are nil.Also I'm using estimote SDK.

Could anyone help me please?Thank you very much.

Here is a short part of my code:

- (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
Could you provide some code?scott
Here is the whole code.Hope this helps youToparceanu Rares

1 Answers

1
votes

Try this:-

         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"]]; 
}

Every time enter,exit even occurs these didlaunchwithoption will be and called u are monitoring the same region again and again, Even though these region will replace the next time when you call startmonitoring.But I have seen some issues related to this, So you must check whether it is already monitoring since u just want to monitor these region only once. TRY AFTER RESTARTING YOUR DEVICE