2014-07-15 26 views
1

我已經創建了一個用於信標的iphone應用程序。在那我想顯示消息,當我退出所有的信標區域。如何在didExitRegion中獲取燈塔主要和次要ID

  1. 我不想顯示每個信標出口區域的消息。例如,如果有3個信標,則只有當我退出所有3個信標時才顯示該信息。有可能這樣做嗎?

  2. ,也是我想在didExitRegion

我用下面的代碼退出的信主要和次要值:

-(void)locationManager:(CLLocationManager*)manager 
    didRangeBeacons:(NSArray*)beacons 
      inRegion:(CLBeaconRegion*)region 
{ 
// Beacon found! 
NSLog(@"iBeacons found"); 
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Successfully found" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; [alert show]; 

CLBeacon *foundBeacon = [beacons firstObject]; 

// You can retrieve the beacon data from its properties 
NSString *uuid = foundBeacon.proximityUUID.UUIDString; 
NSString *majorId = [NSString stringWithFormat:@"%@", foundBeacon.major]; 
NSString *minorId = [NSString stringWithFormat:@"%@", foundBeacon.minor]; 
NSLog(@"UUID: %@", uuid); 
} 

在上面的代碼中我能得到的uuid,主要的,次要的信標。但是我想要獲取didExitRegion中現有信標的值。可能嗎?

在此先感謝。

回答

0

使用可變數組來跟蹤檢測到的信標的區域細節。並通過檢測新的信標區域來更新該陣列。像下面

代碼在委託方法didDetermineState

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region 
{ 
    if(state == CLRegionStateInside) 
    { 
     [regions addObject:region]; // regions is the mutable array 
    } 
} 

而且隨着didExitRegion方法添加

// Tells the delegate that the user left the specified region. 
    - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region 
    { 
     [regions removeObject:region]; 
     CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region; 
     NSLog(@"\nExited region id: %@",beaconRegion.identifier); 
     NSLog(@"\nExited region major: %@",beaconRegion.major); 
     NSLog(@"\nExited region minor: %@",beaconRegion.minor); 

     // Add a check with regions array here to show the custom alert message 

    } 
+1

我試過你的解決方案,我得到的UID,但主要和次要值爲null。任何幫助將是偉大的:) –

0

我不想以顯示每一個信標出口區的消息。例如,對於 示例,如果有3個信標,則僅當我在所有3個信標的出口處退出時才顯示消息。有可能這樣做嗎?

您的要求似乎並不完全清楚。如果這三個信標由您監控的單個區域來描述,那麼很簡單:當您離開區域中最後一個信標的範圍時,您將只收到一條didExitRegion:消息。否則,Alex上面的建議似乎是合理的:跟蹤您正在進入和退出的區域,然後在您當前所在區域的計數降至零時有條件地執行didExitRegion:中的某些代碼。

,也是我想退出的信主要和次要值 didExitRegion

我不知道「退出燈塔」在此明確定義的(你的意思,也就是說,你留下的區域內的最後一個燈塔,因此觸發didExitRegion:消息?),但無論如何,你無法得到你在這裏要求的東西。在Alex記錄majorminor時,它們是被監視(並且在這種情況下退出)的區域的屬性,而不是任何特定的信標

相關問題