Skip to content

Commit

Permalink
Suppressed keyWindow warning and started initial work to support mult…
Browse files Browse the repository at this point in the history
…iple widows out of the box.
  • Loading branch information
ekazaev committed Aug 24, 2020
1 parent ce820a8 commit 019e7c9
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,7 @@

osx_image: xcode11.5
language: swift
cache: cocoapods
cache: cocoapods, slather
podfile: Example/Podfile
before_install:
- gem install slather
Expand Down
4 changes: 4 additions & 0 deletions Example/RouteComposer.xcodeproj/project.pbxproj
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
1BE5406B08BD9E414DF3F05B /* SwiftUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BE54ADDFA896FC6D4244E2B /* SwiftUITests.swift */; };
1BE543AF30CA4A1AA4CBE41A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BE54D8FB7AECC02B9177E13 /* SceneDelegate.swift */; };
1BE54D180F13FDB7C7F7B8C2 /* TestSwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BE5451EE607806BE5D94E97 /* TestSwiftUIView.swift */; };
3964C13C9510D7C17530911E /* Pods_RouteComposer_Example_RouteComposer_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0293FF29C4D706E5D7F4B94 /* Pods_RouteComposer_Example_RouteComposer_Tests.framework */; };
453BC2E32288C6F100314B33 /* ContainerLocatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 453BC2E22288C6F100314B33 /* ContainerLocatorTests.swift */; };
Expand Down Expand Up @@ -174,6 +175,7 @@
0B068CD8E2A01AE34431EC7F /* Pods-RouteComposer_Example-RouteComposer_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RouteComposer_Example-RouteComposer_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-RouteComposer_Example-RouteComposer_Tests/Pods-RouteComposer_Example-RouteComposer_Tests.release.xcconfig"; sourceTree = "<group>"; };
1BE5451EE607806BE5D94E97 /* TestSwiftUIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestSwiftUIView.swift; sourceTree = "<group>"; };
1BE54ADDFA896FC6D4244E2B /* SwiftUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftUITests.swift; sourceTree = "<group>"; };
1BE54D8FB7AECC02B9177E13 /* SceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
453BC2E22288C6F100314B33 /* ContainerLocatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerLocatorTests.swift; sourceTree = "<group>"; };
4552B83C22FDAE2E006E2A5D /* ShortUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShortUITests.swift; sourceTree = "<group>"; };
4570AD292238769C00809A01 /* ExtrasTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtrasTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -352,6 +354,7 @@
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD31AFB9204008FA782 /* Supporting Files */,
847D286E202B7DCC004C1EAF /* StarViewController.xib */,
1BE54D8FB7AECC02B9177E13 /* SceneDelegate.swift */,
);
name = "Example for RouteComposer";
path = RouteComposer;
Expand Down Expand Up @@ -912,6 +915,7 @@
9AFBCE52F3DE5262483447AD /* AnalyticsRouterDecorator.swift in Sources */,
9AFBC4742A536B8AD7957A1A /* Router+Destination.swift in Sources */,
9AFBC4085F7930B60F185C0D /* ExampleNavigationController.swift in Sources */,
1BE543AF30CA4A1AA4CBE41A /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Expand Up @@ -40,8 +40,17 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "RouteComposer_Example.app"
BlueprintName = "RouteComposer_Example"
ReferencedContainer = "container:RouteComposer.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -64,17 +73,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "RouteComposer_Example.app"
BlueprintName = "RouteComposer_Example"
ReferencedContainer = "container:RouteComposer.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -96,8 +94,6 @@
ReferencedContainer = "container:RouteComposer.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
<LocationScenarioReference
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
referenceType = "1">
Expand Down
20 changes: 20 additions & 0 deletions Example/RouteComposer/Info.plist
Expand Up @@ -35,6 +35,25 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>PromptScreen</string>
</dict>
</array>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -51,6 +70,7 @@
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Expand Down
75 changes: 75 additions & 0 deletions Example/RouteComposer/SceneDelegate.swift
@@ -0,0 +1,75 @@
//
// Created by Eugene Kazaev on 24/08/2020.
// Copyright (c) 2020 Evgeny Kazaev. All rights reserved.
//

import Foundation
import UIKit

@available(iOS 13.0.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?

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

// Try in mobile Safari to test the deep linking to the app:
// Try it when you are on any screen in the app to check that you will always land where you have to be
// depending on the configuration provided.
//
// dll://colors?color=AABBCC
// dll://products?product=01
// dll://cities?city=01
ExampleUniversalLinksManager.configure()
if !connectionOptions.urlContexts.isEmpty {
self.scene(scene, openURLContexts: connectionOptions.urlContexts)
}
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let urlContext = URLContexts.first,
let destination = ExampleUniversalLinksManager.destination(for: urlContext.url) else {
return
}

do {
try UIViewController.router.navigate(to: destination)
return
} catch {
return
}
}

func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}

func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}

func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}

func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}

func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}

}
Expand Up @@ -19,7 +19,13 @@ public struct KeyWindowProvider: WindowProvider {

/// `UIWindow` instance
public var window: UIWindow? {
guard let window = UIApplication.shared.keyWindow else {
let keyWindow: UIWindow?
if #available(iOS 13, *) {
keyWindow = UIApplication.shared.windows.first { $0.isKeyWindow }
} else {
keyWindow = UIApplication.shared.keyWindow
}
guard let window = keyWindow else {
assertionFailure("Application does not have a key window.")
return nil
}
Expand Down

0 comments on commit 019e7c9

Please sign in to comment.