ios - didRangeBeacons 没有在 ios 中获取 uuid

标签 ios objective-c xcode

我使用以下代码从特定信标获取消息,但它在 uuid 中始终显示 null。当我运行此代码时,“viewdidLoad 方法工作正常,但当涉及到 didRangebeacons 时,它仅显示最后一个 uuid 信标。实际上,我想检查信标是否可用于特定 uuid 并接收该信号并继续检查数组中的 uuid 和当它接收到另一个信号时,它也应该显示该信标信号。

    - (void)viewDidLoad
{

[super viewDidLoad];

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;

NSLog(@"Before assigning UUID");


NSArray *uuidArr = [NSArray arrayWithObjects: @"9146947B-441D-4116-B60E-4DD4659825AB", @"9146947B-441D-4116-B60E-4DD46598257C", @"9146947B-441D-4116-B60E-4DD46598257B", nil];


for(int i=0; i<[uuidArr count]; i++)

{

NSString *uuidTemp = [uuidArr objectAtIndex:i];

NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidTemp];


self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                             identifier:@"com.gimbal.iosexample"];


[self.locationManager startMonitoringForRegion:self.myBeaconRegion];

[self.locationManager startRangingBeaconsInRegion:self.myBeaconRegion];

if (![CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) 
{


NSString *msg = [NSString stringWithFormat:@"Monitoring not available for  %@", uuidTemp];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Monitoring not available" message:msg delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; 
[alert show]; return;

}

}


}

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

NSLog(@"iBeacons found");

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Successfully found" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; 
[alert show];


self.statusLabel.text = @"iBeacon found!";


CLBeacon *foundBeacon = [beacons firstObject];

NSString *uuid = foundBeacon.proximityUUID.UUIDString;

NSString *major = [NSString stringWithFormat:@"%@", foundBeacon.major];

NSString *minor = [NSString stringWithFormat:@"%@", foundBeacon.minor];

NSLog(@"UUID: %@", uuid);

}


@end

谁能帮我做到这一点。

提前致谢。

最佳答案

您正在 for 循环中创建不同的信标区域,但您的区域标识符相同,因此第二个区域定义将替换第一个,然后第二个区域将被第三个替换。您需要使用唯一的区域标识符 - 类似于

CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                             identifier:[NSString stringWithFormat:@"com.gimbal.iosexample.%d",i]];

关于ios - didRangeBeacons 没有在 ios 中获取 uuid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24155263/

相关文章:

ios - Swift 中的协议(protocol)和委托(delegate)

iphone - 点击 uipickerview 时键盘不退出

objective-c - Objective C 中的安全转换

ios - 文本在容器中无法正确显示(swift 3.0)

objective-c - NSLog on Objects(如UIButton,UIView,NSString,NSDictionary),使用%@作为其描述

ios - 也围绕自身中心旋转物体吗?

ios - 为什么我在 NSURLSession 上收到 SSL_ERROR_ZERO_RETURN 错误

iphone - UILabel 中文本的像素宽度

xcode - 重复弹出: Xcode wants to access key "com.apple.dt.XcodeDeviceMonitor" in your keychain

xcode - NSDocument 和 CoreData 是可能的组合,还是 NSPersistentDocument 是唯一的方法?