繁体   English   中英

iBeacon推动另一种观点! iOS应用

[英]iBeacon to push another view! iOS App

我正在尝试做的是,这样一来,当找到iBeacon时(当用户在主屏幕上时),它将它们发送到应用程序的另一部分。 本质上,它从情节提要中推送了该应用程序的另一个视图。 例如,iBeacon1推送View1,iBeacon2推送View2,依此类推。 就像我说的,我知道这是可能的,但是由于iBeacons相当新,因此没有太多帮助。

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

谢谢您的时间,乔希

如果您使用情节提要,则可以在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但是两者都可以工作。

实用标记-

实用标记-重要方法

-(void)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"];

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM