gpt4 book ai didi

ios - 如何在不知道 iOS 中的 UUID 的情况下检测 ibeacon 设备?

转载 作者:可可西里 更新时间:2023-11-01 05:03:41 27 4
gpt4 key购买 nike

我想开发在不知道 uuid 的情况下检测大量信标设备的应用程序。但是我找不到办法做到这一点。我必须在代码中定义 uuid。

我开发了一个适用于已知设备的 POC。

我的 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;
}
}

那么有没有办法在不知道uuid的情况下检测iBeacon呢?

注意:使用与 check This link 相同功能的示例应用程序广播广播信号(虚拟信标)。

如有任何帮助,我们将不胜感激。

最佳答案

在至少知道信标的 ProximityUUID 的情况下,iOS 中没有公共(public) API 可以检测信标。这是设计使然——Apple 只希望您能够看到自己的信标,这意味着知道 ProximityUUID。

也就是说,操作系统当然知道如何查看任何信标,并且可能有私有(private) API 可用于执行此操作。只需了解您不能使用私有(private) API 为 App Store 开发应用程序,因为 Apple 不会批准使用此类代码。您可以使用私有(private) API 制作一个实用程序来使用您自己的 iOS 设备,但私有(private) API 可能会停止与任何 iOS 升级一起使用

有了这些注意事项,使用 CoreLocation 可以定义一个通配符 CLBeaconRegion,它可用于使用私有(private) API 查找任何信标。 See here对于一种方法。

关于ios - 如何在不知道 iOS 中的 UUID 的情况下检测 ibeacon 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37164085/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com