iBeacon推送另一个视图!iOS应用程序

iBeacon推送另一个视图!iOS应用程序,ios,objective-c,ibeacon,beacon,Ios,Objective C,Ibeacon,Beacon,我试图做到的是,当发现iBeacon时(当用户在主屏幕上时),它会将其发送到应用程序的另一部分。本质上,它从情节提要中推送应用程序的另一个视图。例如,iBeacon1推送View1,iBeacon2推送View2,等等,就是这样。就像我说的,我知道这是可能的,但是因为iBeacons是非常新的,所以没有太多的帮助 如果你能抽出一天的时间来帮助我解决这个我找不到答案的问题,我将不胜感激 谢谢你抽出时间, Josh如果您使用的是故事板,您可以在AppDelegate中执行类似操作: var laun

我试图做到的是,当发现iBeacon时(当用户在主屏幕上时),它会将其发送到应用程序的另一部分。本质上,它从情节提要中推送应用程序的另一个视图。例如,iBeacon1推送View1,iBeacon2推送View2,等等,就是这样。就像我说的,我知道这是可能的,但是因为iBeacons是非常新的,所以没有太多的帮助

如果你能抽出一天的时间来帮助我解决这个我找不到答案的问题,我将不胜感激

谢谢你抽出时间,
Josh

如果您使用的是故事板,您可以在
AppDelegate
中执行类似操作:

var launchedViewControllers = [Int]()

func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
  let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
  if let navController = self.window?.rootViewController?.navigationController {
    for beacon in beacons {
      if (beacon.minor == 1) {
        if !launchedViewControllers.contains(beacon.minor.integerValue) {
          launchedViewControllers.append(beacon.minor.integerValue)
          let viewController1 = mainStoryboard.instantiateViewControllerWithIdentifier("viewController1")
          navController.pushViewController(viewController1, animated: true)
        }
      }
      if (beacon.minor == 2) {
        if !launchedViewControllers.contains(beacon.minor.integerValue) {
          launchedViewControllers.append(beacon.minor.integerValue)
          let viewController2 = mainStoryboard.instantiateViewControllerWithIdentifier("viewController1")
          navController.pushViewController(viewController2, animated: true)
        }
      }
    }
  }
}
您也可以将其重写为使用segues,而不是使用
NavigationController
以编程方式推送
ViewControllers
,但两者都可以工作。

pragma mark- pragma标记-重要方法 -(无效)showSecondController{

if ([_beacon.major isEqual: @3404] && [_beacon.minor isEqual: @10692]) {
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SDOVideoDetailController"];
    
} else if ([_beacon.major isEqual: @20165] && [_beacon.minor isEqual: @53849]) {
    
    
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LRCVideoDetailController"];
    
}  else if ([_beacon.major isEqual: @53088] && [_beacon.minor isEqual: @30487]) {
    
    
    
    
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CECSVideoDetailController"];
    
    
    
}  else if ([_beacon.major isEqual: @55304] && [_beacon.minor isEqual: @59835]) {
    
    
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"IVideoDetailController"];
    
}  else if ([_beacon.major isEqual: @16004] && [_beacon.minor isEqual: @46054]) {
    
    
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CILVideoDetailController"];
    
}  else if ([_beacon.major isEqual: @20214] && [_beacon.minor isEqual: @11696]) {
    
    
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ITVideoDetailController"];
    
}  else if ([_beacon.major isEqual: @21559] && [_beacon.minor isEqual: @17557]) {
    
    
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PARKVideoDetailController"];
    
}  else if ([_beacon.major isEqual: @59452] && [_beacon.minor isEqual: @21013]) {
    
    
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SCVideoDetailController"];
    
}  else if ([_beacon.major isEqual: @42093] && [_beacon.minor isEqual: @49773]) {
    
    
    
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
        
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    
    
    self.secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"BAVideoDetailController"];
    
}

将新的视图控制器推到导航堆栈上后,立即停止测距可能也是一个好主意(:我认为提问者希望保持测距,因此,如果不同的信标进入视野,则会启动不同的视图控制器。这就是为什么我建议的解决方案中会显示视图控制器是否已启动的标志(以防止重复启动。)