2014-06-11 27 views
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 

誰能幫助我做到這一點。

感謝。

回答

1

你在你的for循環創建不同的信標區,但是你的區域標識符是相同的,所以第二個區域定義將被替換第一個,然後第二個將被第三個替換。您需要使用唯一的區域標識符 - 類似

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