2016-01-16 4 views
0

Я пытаюсь сделать так, чтобы, когда iBeacon был найден (когда пользователь находится на главном экране), он отправляет их в другую часть приложения. По сути, он выдвигает другой вид приложения из раскадровки. Например, iBeacon1 толкает View1, iBeacon2 толкает View2 и т. Д., И все. Как я уже сказал, я знаю, что это возможно, но поскольку iBeacons являются совершенно новыми, доступ к ним мало.iBeacon, чтобы нажать еще один вид! Приложение iOS

Я был бы очень признателен, если бы вы могли потратить некоторое время на свой день, чтобы помочь мне в решении этой проблемы, на которую я не могу найти ответ.

Спасибо за ваше время, Джош

ответ

0

Если вы используете раскадровки, вы могли бы сделать что-то подобное в вашем 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) 
     } 
     } 
    } 
    } 
} 

Вы также можете переписать это использование перетекает вместо программно нажав ViewControllers используя NavigationController, но оба будут работать.

+0

также может быть хорошей идеей, чтобы немедленно прекратить начиная после нажатия на новый контроллер представления на Навигационный стек (: – heypiotr

+0

Я думаю, что вопрошающий хочет сохранить дальность действия, поэтому, если появляется другой маяк, запускается другой контроллер представлений. Именно поэтому в моем предлагаемом решении есть флаги для того, запущены ли диспетчеры представлений (для предотвращения повторных запусков). – davidgyoung

0

Прагма знак -

Прагма знак Методы -Важно

- (Недействительными) 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"]; 

} 
Смежные вопросы