ios - How do I use CoreLocation to get multiple iBeacons? -


i'm trying use corelocation multiple ibeacons specified ios app- idea if they're in range, it'll notify me each 1 finds them.

the problem in didenterregion , didexitregion methods, have provide clbeaconregion object. there's 1 of these every ibeacon, , if using 1 ibeacon, use one, since there several, need know how find each clbeaconregion methods.

maybe i'm misunderstanding how works; if so, please let me know.

- (void)getforuuuids:(cdvinvokedurlcommand *)command {         //get array of uuid's filter         self->locationuuids = [self getargsobject:command.arguments];          self->locationmanager = [[cllocationmanager alloc] init];         self->locationmanager.delegate = self;         scancallback = command.callbackid;          for(nsinteger = 0; < [locationuuids count]; i++) {             nsstring *identifier = [nsstring stringwithformat:@"bleregion %d",i];             clbeaconregion *thisregion = [[clbeaconregion alloc] initwithproximityuuid:[[locationuuids  allkeys] objectatindex:i] identifier:identifier];             [self->locationmanager startmonitoringforregion:thisregion];         } }      - (void)locationmanager:(cllocationmanager*)manager didenterregion:(clregion*)region {     [self->locationmanager startrangingbeaconsinregion:????]; }  -(void)locationmanager:(cllocationmanager*)manager didexitregion:(clregion*)region {     [self->locationmanager stoprangingbeaconsinregion:????]; } 

ranging on same region fired monitor entry/exit event extremely simple:

- (void)locationmanager:(cllocationmanager*)manager didenterregion:(clregion*)region {     [self->locationmanager startrangingbeaconsinregion:(clbeaconregion *)region]; } 

this start ranging on exact same region used start monitoring. note there region parameter passed callback. region parameter include same uuid set before.

one other point: while there nothing wrong starting ranging when enter region , stopping ranging when exit region, there no need this. start ranging same time start monitoring. because ranging won't when ibeacon isn't visible, end result identical. difference first ranging callback 1 second sooner if set ahead of time. there no drain on battery or system resources.

the added benefit of setting ahead of time don't have casting of clregion object -- have original object begin with. , don't have implement monitoring callback methods, code simpler. this:

- (void)getforuuuids:(cdvinvokedurlcommand *)command {     //get array of uuid's filter     self->locationuuids = [self getargsobject:command.arguments];      self->locationmanager = [[cllocationmanager alloc] init];     self->locationmanager.delegate = self;     scancallback = command.callbackid;      for(nsinteger = 0; < [locationuuids count]; i++) {         nsstring *identifier = [nsstring stringwithformat:@"bleregion %d",i];         clbeaconregion *thisregion = [[clbeaconregion alloc] initwithproximityuuid:[[locationuuids  allkeys] objectatindex:i] identifier:identifier];         [self->locationmanager startmonitoringforregion:thisregion];         [self->locationmanager startrangingbeaconsinregion:thisregion];     } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -