带条件情节提要的SceneDelegate

时间:2020-04-21 20:39:15

标签: ios xcode

在Xcode 11之前,可以有条件地在AppDelegate内的iOS应用上设置从哪个Storyboard开始。现在,通过添加SceneDelegate,据我了解,您可以在那里实例化相同的逻辑,而我对此有疑问。

如果将Storyboard Name设置在Application Scene Manifest内,则可以使该应用始终在同一情节提要中启动,但我想有条件地在两个情节提要之一中启动。

我已经尝试过设置Storyboard Name且未在Application Scene Manifest内设置这样的事情,但是似乎什么也没用。有任何想法吗?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let _ = scene as? UIWindowScene else {return}

    let storyboard: UIStoryboard
    let initViewController: UIViewController

    if (User.sharedInstance.isLoggedIn()) {
        storyboard = UIStoryboard(name: "Main", bundle: nil)
        initViewController = storyboard.instantiateViewController(withIdentifier: "MainTabs") as UIViewController
        self.window?.rootViewController = initViewController
    } else {
        storyboard = UIStoryboard(name: "Login", bundle: nil)
        initViewController = storyboard.instantiateViewController(withIdentifier: "LoginLanding") as UIViewController
        self.window?.rootViewController = initViewController
    }

    self.window?.makeKeyAndVisible()
}

1 个答案:

答案 0 :(得分:0)

问题似乎是我没有在场景中设置窗口。

library(leaflet)
library(htmltools)
library(htmlwidgets)


LeafletSideBySidePlugin <- htmlDependency("leaflet-side-by-side","2.0.0",
                                          src = c(href="https://cdn.jsdelivr.net/gh/digidem/leaflet-side-by-side@2.0.0/"),
                                          script="leaflet-side-by-side.js")

# A function that takes a plugin htmlDependency object and adds
# it to the map. This ensures that however or whenever the map
# gets rendered, the plugin will be loaded into the browser.

registerPlugin <- function(map, plugin) {
  map$dependencies <- c(map$dependencies, list(plugin))
  map
}

leaflet() %>% addTiles() %>%
  setView(lng = 12, lat = 50, zoom = 4) %>%
  # Register leaflet-side-by-side plugin on this map instance
  registerPlugin(LeafletSideBySidePlugin) %>%
  onRender("
        function(el, x) {
          var mylayer1 = L.tileLayer(
            'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
             maxZoom: 18
             }).addTo(this);
          var mylayer2 = L.tileLayer(
          '//stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png',{
             maxZoom: 14
             }).addTo(this);
        L.control.sideBySide(mylayer1, mylayer2).addTo(this);
        }")