2017-05-10 1 views
0

J'ai essayé avec ce code mais les délégués n'appellent pas et n'arrêtent pas le balayage, à une condition particulière je dois appeler une autre fonction.Comment arrêter le balayage d'iBeacon

-(void)locationManager:(CLLocationManager *)manager stopRangingBeaconsInRegion:(CLBeaconRegion *)region 

{ 
NSLog(@"STOP PLEASEEEEEEEE"); 

} 


- (void)locationManager:(CLLocationManager *)manager stopMonitoringForRegion:(CLRegion *)region { 

NSLog(@"didExitRegion"); 
[manager stopRangingBeaconsInRegion:(CLBeaconRegion*)region]; 
NSLog(@"StopRangingBeacons"); 

} 

je utilise ce code pour démarrer le beaconScanning

-(void)loadUIElements 
{ 

self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.delegate = self; 


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND , 0), ^{ 
    self.beaconRegionAny = [[AIBBeaconRegionAny alloc] initWithIdentifier:@"Any"]; 
    [self.locationManager requestWhenInUseAuthorization]; 
    self.locationManager.pausesLocationUpdatesAutomatically = YES; 
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegionAny]; }); 

} 

appeler cette fonction lors de commencer à surveiller les balises

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region 

{

+1

double possible de [Il est possible que stopRangingBeaconsInRegion arrêter les notifications d'une région contrôlée?] (Http://stackoverflow.com/questions/27912025/it-is- possible-que-stoprangingbeaconsinregion-stop-notifications-of-a-monitoring) – Lepidopteron

+1

Avez-vous regardé ici? Cela semble être un problème similaire? http://stackoverflow.com/questions/27912025/it-is-possible-that-stoprangingbeaconsinregion-stop-notifications-of-a-monitored – Lepidopteron

+0

@Lepidopteron Oui mais j'ai besoin de cet événement alors seulement je peux passer à l'étape suivante. Ce qui me préoccupe, c'est que lorsque la recherche d'une balise aura lieu un moment, je veux arrêter la numérisation, utiliser ces données pour appeler une autre fonction. – Manju

Répondre

0

Vous devez supprimer l'auditeur de votre monitoredRegions liste en utilisant stopMonitoring(for:). Voici un lien vers le documentation

Avez-vous essayé?

[self.locationManager stopMonitoringForRegion:self.beaconRegionAny]; 
+0

Oui, j'ai essayé la numérisation continue sans interruption et toujours à - (void) locationManager: Gestionnaire (CLLocationManager *) didRangeBeacons: (NSArray *) balises inRegion: (CLBeaconRegion *) région – Manju

+0

NSUUID * myUUID = [[NSUUID alloc] initWithUUIDString: @ "11111111111111111111111111111111"]; CLBeaconRegion * region = [[CLBeaconRegion alloc] initWithProximityUUID: identificateur myUUID: @ "monCompagnie"]; cet UDID est l'identifiant de la balise ou notre identifiant de l'appareil ou autre chose – Manju

0

créer une action de bouton et cette ligne de code.

@IBAction func launchButtonClicked(_ sender: Any) { 
    // Determine action based on button state 
    switch (launchButton.currentState) { 
    case .Start: 
     beaconManager.startRangingBeacons(in: region) 
     launchButton.currentState = .Stop 
    case .Stop: 
     beaconManager.stopRangingBeacons(in: region) 
     launchButton.currentState = .Start 
    } 
} 

Essayez de cette façon, cela fonctionne

+0

Pouvez-vous s'il vous plaît donner une solution dans l'objectif c et ces fonctions veulent faire automatiquement en arrière-plan – Manju