2014年7月4日 星期五

iBeacon心得

1.只支援iOS7以上。Android 4.3以上。

2.只支援iPhone4S以上、iPad 第三代以上、iPad mini、iPod touch第五代以上。

3.iOS7.0.6 無法支援背景移除之後的定位更新,所以無法觸發ibeacon
iOS7.1.2可以在背景可以在移除之後,仍然能監控定位更新,所以能觸發ibeacon

4.iOS 7.1.1以前,會有手機完成掃不到ibeacon的問題,要重開機之後才能掃到,升級7.1.2之後這個問題就不再發生。

5.iBeacon : What is the difference between didEnterRegion and didDetermineState(CLRegionStateInside)
結論:
didEnterRegion / didExitRegion觸發時機

  1. 當地區轉移時,才觸發這二個方法

didDetermineState

  1. didEnterRegion / didExitRegion被呼叫時,被觸發
  2. 當requestStateForRegion被呼叫時,也會觸發
  3. 當BeaconRegion的notifyEntryStateOnDisplay被設為YES時,當使用者打開iPhone螢幕時,也會被觸發。


The location manager calls this method whenever there is a boundary transition for a region. It calls this method in addition to calling the locationManager:didEnterRegion: and locationManager:didExitRegion: methods. The location manager also calls this method in response to a call to its requestStateForRegion: method, which runs asynchronously.
So didDetermineState should get called whenever didEnterRegion/didExitRegion do. In addition, if you explicitly request the state via requestStateForRegion it will be called.
There's one other behaviour that triggers this method: if you're monitoring a region on which you've enabled the notifyEntryStateOnDisplay property, the method will be called whenever the user wakes their device manually, and they are within the region you are monitoring. From the documentation
When set to YES, the location manager sends beacon notifications when the user turns on the display and the device is already inside the region. These notifications are sent even if your app is not running. In that situation, the system launches your app into the background so that it can handle the notifications. In both situations, the location manager calls the locationManager:didDetermineState:forRegion: method of its delegate object.

6.監控beacon region的方法
使用startMonitoringForRegion:或startRangingBeaconsInRegion來啟用進入離開region的監控:
二種方式的差別在於Monitoring是以GPS的監控頻率(未知)為主,而RangingBeacons是以藍牙收廣播頻率為主(一秒一次)

//只要有狀態(unknown, inside, outside)改變時觸發:
- (void)locationManager:(CLLocationManager *)manager
      didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
//進入區域時觸發:
- (void)locationManager:(CLLocationManager *)manager
          didExitRegion:(CLRegion *)region
//離開區域時觸發:
- (void)locationManager:(CLLocationManager *)manager
         didEnterRegion:(CLRegion *)region

使用startRangingBeaconsInRegion來啟用beacon在region內的監控:
只要有手機有掃到你指定的beacon,didRangeBeacons就會被觸發,你可以在其中讀取目前beacon的狀態
- (void)locationManager:(CLLocationManager *)manager
        didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
CLBeaconRegion
You can monitor beacon regions in two ways. To receive notifications when a device enters or exits the vicinity of a beacon, use the startMonitoringForRegion: method of your location manager object. While a beacon is in range, you can also call the startRangingBeaconsInRegion: method to begin receiving notifications when the relative distance to the beacon changes.

在重開機之後會發生問題:
一,location沒有被立刻啟動,會無法偵測。
二,要重新開關一次藍牙,才會收到ibeacon,有可能是藍牙有休眠機制?

使用peripheralDataWithMeasuredPower:nil和startAdvertising來實作beacon:
time_t t;

srand((unsigned) time(&t));
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:_beaconRegion.proximityUUID major:rand() minor:rand()
                                                                identifier:_beaconRegion.identifier];

    NSDictionary *beaconPeripheralData = [region peripheralDataWithMeasuredPower:nil];
    NSLog(@"beaconPeripheralData : %@", beaconPeripheralData);

    [_peripheralManager startAdvertising:beaconPeripheralData];

7,要在AppDelegate.m中啟用beaconManager才會在背景移除情況下被觸發。

Estimote的廣播

02 01 06 //Flag[0~2]
1A       //Length
FF       //Type
4C 00    //Company ID
02 15    //Beacon Type
B9 40 7F 30 F5 F8 46 6E AF F9 25 55 6B 57 FE 6D //Proximity UUID
B1 98    //Major
B6 2E    //Minor
B6       //Measured Power
09 09 65 73 74 69 6D 6F 74 65 0E 16 0A 18 98 B1 2E B6 66 FC B6 98 B1 2E B6 00 00 00 00 00 00 00

沒有留言:

張貼留言