iBeacon 和 BLE 的差異

August 22, 2017 0 Comments

1. Use Core Location framework to find iBeacon's distance.

使用CLLocationManagerDelegate  抓取Beacon 和裝置間的距離
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
        didRangeBeacons:(NSArray *)beacons
               inRegion:(CLBeaconRegion *)region {
 
   if ([beacons count] > 0) {
      CLBeacon *nearestExhibit = [beacons firstObject];
 
      // Present the exhibit-specific UI only when
      // the user is relatively close to the exhibit.
      if (CLProximityNear == nearestExhibit.proximity) {
         [self presentExhibitInfoWithMajorValue:nearestExhibit.major.integerValue];
      } else {
         [self dismissExhibitInfo];
   }
}

https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html

2. Use Core Bluetooth framework to communicate with BLE device.

在架構中有分Centrals(手機端) 和 Peripherals(裝置端) , Centrals 由CBCentralManager 這個物件來管理和Peripherals連線的事宜. 而裝置端則是 CBPeripheral  . CBPeripheral 下會有 CBService  代表不同的服務.
以上使用時需用到 CBCentralManagerDelegate, CBPeripheralDelegate 這兩個delegate.


例如在CBCentralManagerDelegate內有 centralManager(_:didDiscover:advertisementData:rssi:) 這個method, 透過rssi 我們可以知道裝置連線的訊號強弱判斷與裝置間的距離.



https://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor

0 comments: