2016-05-24 38 views
1

如果打開藍牙和定位服務,我可以成功掃描信標。但是我想知道當藍牙處於開啓模式並且位置服務處於關閉模式時,是否有任何方法可以掃描信標。是否可以使用目標C掃描位置服務禁用的信標?

我已經使用這個代碼,但是當位置服務處於關閉狀態

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

任何人都可以請詳細說明我們如何能夠掃描指路明燈。沒有位置的服務不叫這個委託方法?

在此先感謝。

+0

是的,你可以做我猜。 –

回答

1

不,我不認爲你可以在位置服務關閉的情況下使用系統iBeacon支持。 iBeacon支持由Core Location框架提供。

您可能可以編寫低級別的BLE代碼來查找來自iBeacons的消息,但我已經看到來自無法弄清楚如何實現該操作的人的帖子。此外,您將失去Core Location提供的優勢,例如即使在檢測到信標時您的應用程序未運行,也會收到關於信標的通知。

+0

感謝您的回答。但是Google Crome如何能夠掃描信標甚至位置服務關閉?正如我們在Crome的widget中看到的最近的燈塔。你能分享一下這個背後的一些想法嗎? –

+0

我懷疑他們有自己的BLE庫來檢測iBeacons。 –

0

不,您不能在沒有定位服務的情況下使用iBeacon。檢查什麼蘋果文檔據說:

iBeacon與iOS中的位置服務工作。藉助iBeacon,您的iOS 設備可以在您接近或離開某個位置時提醒應用程序。在 除了監控您的位置之外,應用程序還會知道您何時將 關閉至iBeacon,例如零售商店中的結帳櫃檯。使用緯度和經度來確定您的位置,而不是使用 確定您的位置,iBeacon使用 Bluetooth設備檢測到的低能量信號。

欲瞭解更多詳情,您可以閱讀Apple support for iBracon

希望這將有助於:)

1

使用藍牙上,但位置關閉,可以探測藍牙LE信標設備只能與CoreBluetooth的API,而不是與CoreLocation蜜蜂。

這有效地防止從檢測iBeacon顯示的傳輸,因爲iOS的塊它們的檢測經由CoreBluetooth。看到我的博客文章在這裏:http://developer.radiusnetworks.com/2013/10/21/corebluetooth-doesnt-let-you-see-ibeacons.html

但是,您可以使用CoreBluetooth來檢測其他信標格式,如AltBeacon和Eddystone。我有開放的源代碼顯示如何與iOS beacon tools做到這一點。

使用上面的工具,這裏是掃描AltBeacon的例子,埃迪斯通,UID,埃迪斯通-URL和埃迪斯通-EID,並記錄標識檢測:

self.beaconParsers = [[NSMutableArray alloc] init]; 
RNLBeaconParser *altBeaconParser = [[RNLBeaconParser alloc] init]; 
[altBeaconParser setBeaconLayout:@"m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25" error: Nil ]; 
RNLBeaconParser *uidBeaconParser = [[RNLBeaconParser alloc] init]; 
[uidBeaconParser setBeaconLayout:@"s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19" error: Nil]; 
RNLBeaconParser *urlBeaconParser = [[RNLBeaconParser alloc] init]; 
[urlBeaconParser setBeaconLayout:@"s:0-1=feaa,m:2-2=10,p:3-3:-41,i:4-20v" error: Nil]; 
RNLBeaconParser *eidBeaconParser = [[RNLBeaconParser alloc] init]; 
[eidBeaconParser setBeaconLayout:@"s:0-1=feaa,m:2-2=30,p:3-3:-41,i:4-11" error: Nil]; 
self.beaconParsers = @[ altBeaconParser, uidBeaconParser, urlBeaconParser, eidBeaconParser ]; 
self.cbManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue() 
                options:@{ CBCentralManagerOptionRestoreIdentifierKey: 
                   @"myCentralManagerIdentifier" }]; 

... 

- (void)centralManagerDidUpdateState:(CBCentralManager *)central { 
    if (central.state == CBCentralManagerStatePoweredOn && self.scanning) { 
    CBUUID *eddystone16BitUUID = [CBUUID UUIDWithString:@"FEAA"]; 
    NSLog(@"eddy uuid is %@", [eddystone16BitUUID UUIDString]); 
    [self.cbManager scanForPeripheralsWithServices:@[eddystone16BitUUID] options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @(YES)}]; 
    // this scans for BLE peripherals including beacons 
    [self.cbManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @(YES)}]; 

    } 
    else { 
    if (central.state == CBCentralManagerStateUnknown) { 
     NSLog(@"CoreBluetooth state UNKNOWN"); 
    } 
    else if (central.state == CBCentralManagerStateResetting) { 
     NSLog(@"CoreBluetooth state RESETTING"); 
    } 
    else if (central.state == CBCentralManagerStateUnsupported) { 
     NSLog(@"CoreBluetooth state UNSUPPORTED"); 
    } 
    else if (central.state == CBCentralManagerStateUnauthorized) { 
     NSLog(@"CoreBluetooth state UNAUTHORIZED"); 
    } 
    else if (central.state == CBCentralManagerStatePoweredOff) { 
     NSLog(@"CoreBluetooth state POWERED OFF"); 
    } 
    } 
} 


- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { 
    NSDictionary *serviceData = advertisementData[@"kCBAdvDataServiceData"]; 

    RNLBeacon *beacon = Nil; 
    NSData *adData = advertisementData[@"kCBAdvDataManufacturerData"]; 

    for (RNLBeaconParser *beaconParser in self.beaconParsers) { 
    if (adData) { 
     beacon = [beaconParser fromScanData: adData withRssi: RSSI forDevice: peripheral serviceUuid: Nil]; 
     beacon.bluetoothIdentifier = [peripheral.identifier UUIDString]; 
    } 
    else if (serviceData != Nil) { 
     for (NSObject *key in serviceData.allKeys) { 
     NSString *uuidString = [(CBUUID *) key UUIDString]; 
     NSScanner* scanner = [NSScanner scannerWithString: uuidString]; 
     unsigned long long uuidLongLong; 

     [scanner scanHexLongLong: &uuidLongLong]; 
     NSNumber *uuidNumber = [NSNumber numberWithLongLong:uuidLongLong]; 

     NSData *adServiceData = [serviceData objectForKey:key]; 
     if (adServiceData) { 
      beacon = [beaconParser fromScanData: adServiceData withRssi: RSSI forDevice: peripheral serviceUuid: uuidNumber]; 
     } 
     } 
    } 
    if (beacon != Nil) { 
     break; 
    } 
    } 

    if (beacon != Nil) { 
    NSString *key = [NSString stringWithFormat:@"%@ %@ %@", beacon.id1, beacon.id2, beacon.id3]; 
    NSLog(@"Detected beacon: %@", key); 
} 
+0

但是Crome小部件能夠掃描IBeacon,即使位置服務已關閉。你能分享你的知識嗎? –

+0

Chrome小部件掃描Eddystone-URL傳輸,而不是iBeacon傳輸。這就是沒有CoreLocation的原因。在這裏看到更多:http://developer.radiusnetworks.com/2015/07/22/how-to-push-messages-without-an-app.html – davidgyoung

+0

看到我的答案編輯與測試鏈接演示你不能檢測iBeacon用CoreBluetooth和代碼來檢測CoreBluetooth的其他信標格式。 – davidgyoung

相關問題