gpt4 book ai didi

ios - 如何在 IOS 中扫描信标?

转载 作者:行者123 更新时间:2023-11-29 01:22:14 24 4
gpt4 key购买 nike

我正在开发一个应用程序来搜索最近的信标设备,但无法调用任何代表,我已经有可用的信标,但找不到任何信标。

我也不明白 NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"3863C90B-1BA6-4A4E-ADD2-D64FF1286898"]; static 是通过还是不通过?

 NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"3863C90B-1BA6-4A4E-ADD2-D64FF1286898"];
self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
identifier:@"com.jss.myidentifire"];

self.myBeaconRegion.notifyOnEntry = YES;
[self.locationManager startMonitoringForRegion:self.myBeaconRegion];
[self.locationManager startUpdatingHeading];
[self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
[locationManager requestStateForRegion:region];
}
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if (state == CLRegionStateInside)
{
[self locationManager:locationManager didEnterRegion:region];
}

}
- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion *)region
{
// We entered a region, now start looking for our target beacons!
self.statusLabel.text = @"Finding beacons.";
[self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"BeaconDetail" message:@"DidEnterRegion Called" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion *)region
{
// Exited the region
self.statusLabel.text = @"None found.";
[self.locationManager stopRangingBeaconsInRegion:self.myBeaconRegion];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"BeaconDetail" message:@"didExitRegion Called" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];

}
-(void)locationManager:(CLLocationManager*)manager
didRangeBeacons:(NSArray*)beacons
inRegion:(CLBeaconRegion*)region
{
self.statusLabel.text = @"Beacon found!";
CLBeacon *foundBeacon = [beacons firstObject];
NSString *uuid = foundBeacon.proximityUUID.UUIDString;
NSString *major = [NSString stringWithFormat:@"%@", foundBeacon.major];
NSString *minor = [NSString stringWithFormat:@"%@", foundBeacon.minor];
NSString *accuracy = [NSString stringWithFormat:@"%f", foundBeacon.accuracy];
accuracy = [NSString stringWithFormat:@"%f", foundBeacon.accuracy];

if (foundBeacon.proximity == CLProximityUnknown) {
self.distanceLabel.text = @"Unknown Proximity";
} else if (foundBeacon.proximity == CLProximityImmediate) {
self.distanceLabel.text = @"Immediate";
} else if (foundBeacon.proximity == CLProximityNear) {
self.distanceLabel.text = @"Near";
} else if (foundBeacon.proximity == CLProximityFar) {
self.distanceLabel.text = @"Far";
}

NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:uuid forKey:@"uuid"];
[dict setObject:major forKey:@"major"];
[dict setObject:minor forKey:@"minor"];
[dict setObject:accuracy forKey:@"accuracy"];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"BeaconDetail" message:[NSString stringWithFormat:@"%@",dict] delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}

最佳答案

通过添加以下内容确保您已获得扫描信标的权限:

if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}

要使上述工作正常,您还需要向 Info.plist 文件添加一个新 key :NSLocationAlwaysUsageDescription将值设置为“此应用想要扫描信标”之类的值

关于ios - 如何在 IOS 中扫描信标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34460585/

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