Ranging Beacons in iOS 10

て烟熏妆下的殇ゞ 提交于 2019-12-04 12:04:06

问题


In my app, I use Beacon Region Monitoring in CoreLocation. The app sets 2 proximityUUID as region (they have different id), and start ranging like following.

#pragma mark - CLLocationManagerDelegate

(void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region {
     [self.locationManager requestStateForRegion:(CLBeaconRegion *)region];
}

- (void)locationManager:(CLLocationManager *)manager 
didExitRegion:(CLRegion *)region {
     [self.locationManager stopRangingBeaconsInRegion:(CLBeaconRegion *)region]; 
}

- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{ 
    for(CLBeacon* b in beacons){
         //output only previous beacon if it's before regionout to previous region
         NSLog(@"%@",b);
    }
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
     //error
}

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{ 
   if(state == CLRegionStateInside){
        if ([region isMemberOfClass:[CLBeaconRegion class]] && [CLLocationManager isRangingAvailable]){
            [self.locationManager startRangingBeaconsInRegion:(CLBeaconRegion *)region];
        }
  }
}

It works in iOS 8 and iOS 9, but it does not work in iOS 10.

[in iOS 8/iOS 9]

1.broadcast beacon1

2.[app]didRangeBeacons (beacon1)

3.stop beacon1 and broadcast beacon2

4.[app]didRangeBeacons (beacon2)

[iOS 10]

1.broadcast beacon1

2.[app]didRangeBeacons (beacon1)

3.stop beacon1 and broadcast beacon2

4.[app]didRangeBeacons (**beacon1**)

Is it a bug of iOS 10?


回答1:


Ok, I had the same problem in Swift 3 but I resolved it.

There seem to be two things (that are probably directly related):

  • for iOS10 the advertising interval of the beacon might be set too high (set it to about 200ms and then it should work on both 9 & 10 as advised by dantastic on Macrumors)

  • how I got it working again: I tested it on an iPad with iOS 9.3.5 and needed to change the Deployment target to 9.3. That showed it was working again both on my iPad with iOS 9, but... also resolved it on my iOS 10 devices.



来源:https://stackoverflow.com/questions/39339835/ranging-beacons-in-ios-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!