ストーリーボードを使用している場合は、次のようなことができます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)
}
}
}
}
}
ViewControllersaを使用してプログラムでプッシュする代わりに、セグエを使用するようにこれを書き直すこともできますNavigationControllerが、どちらも機能します。