Ich möchte App entwickeln, die eine Menge von Beacon-Gerät erkennt, ohne Uuid zu kennen. Jedoch kann ich keinen Weg finden, dies zu tun. Ich muss UUID im Code definieren.Wie kann ich Ibeacon-Gerät erkennen, ohne UUID in iOS zu kennen?
Ich habe eine POC entwickelt, die mit bekannten Geräten funktioniert.
Code My-View-Controller:
-(void)setUpview
{
// Regardless of whether the device is a transmitter or receiver, we need a beacon region.
NSUUID * uid = [[NSUUID alloc] initWithUUIDString:@"78CDC73D-D678-4B35-A88A-C2E09E5B963F"];//[UIDevice currentDevice].identifierForVendor;
treasureId = @"com.eden.treasure";
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uid identifier:treasureId];
// Location manager.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startMonitoringForRegion:self.beaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
[self locationManager:self.locationManager didStartMonitoringForRegion:self.beaconRegion];
[self.beaconRegion setNotifyEntryStateOnDisplay:YES];
[self.beaconRegion setNotifyOnEntry:YES];
[self.beaconRegion setNotifyOnExit:YES];
// self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
if ([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad || [[[UIDevice currentDevice] model] isEqualToString:@"iPad Simulator"])
{
[self configureTransmitter];
}
else {
[self configureReceiver];
}
}
-(void)configureTransmitter
{
// The received signal strength indicator (RSSI) value (measured in decibels) for the device. This value represents the measured strength of the beacon from one meter away and is used during ranging. Specify nil to use the default value for the device.
NSNumber * power = [NSNumber numberWithInt:-63];
self.peripheralData = [self.beaconRegion peripheralDataWithMeasuredPower:power];
// Get the global dispatch queue.
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// Create a peripheral manager.
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:queue];
}
-(void)configureReceiver {
// Location manager.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
[self.locationManager startMonitoringForRegion:self.beaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
#pragma mark - CBPeripheralManagerDelegate methods
-(void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral
{
// The peripheral is now active, this means the bluetooth adapter is all good so we can start advertising.
if (peripheral.state == CBPeripheralManagerStatePoweredOn)
{
[self.peripheralManager startAdvertising:self.peripheralData];
}
else if (peripheral.state == CBPeripheralManagerStatePoweredOff)
{
NSLog(@"Powered Off");
[self.peripheralManager stopAdvertising];
}
}
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if(state == CLRegionStateInside)
{
NSLog(@"%@",[NSString stringWithFormat:@"You are inside region %@", region.identifier]);
}
else if(state == CLRegionStateOutside)
{
NSLog(@"%@",[NSString stringWithFormat:@"You are outside region %@", region.identifier]);
}
else
{
return;
}
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
if ([beacons count] == 0)
return;
NSString * message;
UIColor * bgColor;
CLBeacon * beacon = [beacons firstObject];
switch (beacon.proximity) {
case CLProximityUnknown:
message = [NSString stringWithFormat:@"ProximityUnknown -- %ld", (long)beacon.proximity];
bgColor = [UIColor blueColor];
break;
case CLProximityFar:
message = [NSString stringWithFormat:@"ProximityFar -- %ld", (long)beacon.proximity];
bgColor = [UIColor colorWithRed:.0f green:.0f blue:230.0f alpha:1.0f];
break;
case CLProximityNear:
message = [NSString stringWithFormat:@"ProximityNear -- %ld", (long)beacon.proximity];
bgColor = [UIColor orangeColor];
break;
case CLProximityImmediate:
default:
message = [NSString stringWithFormat:@"ProximityImmediate -- %ld", (long)beacon.proximity];
bgColor = [UIColor redColor];
break;
}
if (beacon.proximity != self.previousProximity)
{
[lblStatus setText:message];
[self.view setBackgroundColor:bgColor];
self.previousProximity = beacon.proximity;
}
}
So ist es eine Möglichkeit, IBeacon zu erfassen, ohne zu wissen, UUID?
Hinweis: Beispielanwendung, die die gleiche Funktion wie check This link Broadcastsendung (Virtual Beacons) verwendet.
Jede Hilfe würde sehr geschätzt werden.
Sie sollten nicht in der Lage sein, es zu tun. Wenn es ein REAL iBeacon ist (und kein Hybrid zwischen einem klassischen BLE-Gerät und einem iBeacon). iOS sollte die BLE-Broadcast-Nachricht automatisch übersetzen und sie nur für CLBeacon-Dateien verfügbar machen. Wenn es sich um einen Hybrid handelt, der manchmal klassisches BLE-Material sendet, können Sie es mit CBPeripheralManager finden und die UUID nach CLBeacon durchsuchen lassen. Das Hauptproblem ist, dass iOS nur High-Level-APIs und keine Low-Level-APIs bereitstellt, während sie für Android die Nachricht selbst analysieren und so scannen und als Reaktion darauf reagieren können, was immer sie wollen. – Larme
Sie müssen wissen, die UUID, die Sie suchen. Sie können nicht nach allen UUIDs scannen – Paulw11