0
我使用以下代碼從特定的信標中獲取消息,但它始終在uuid中顯示爲空。當我運行這個代碼時,「viewdidLoad方法工作正常,但是當涉及到didRangebeacons時,它只顯示最後的uuid信標。實際上,我想檢查是否可用於特定uuid的信標,並接收該信號並繼續檢查數組中的uuids,當它接收到的另一個信號,應該提前顯示信標信號也。didRangeBeacons在ios中沒有獲取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
誰能幫助我做到這一點。
感謝。