Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Example/SMSecureTaskSwitcher/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import SMSecureTaskSwitcher
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var secureTaskSwitcher: SMSecureTaskSwitcher?
var secureTaskSwitcher: SecureTaskSwitcher?

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
secureTaskSwitcher = SMSecureTaskSwitcher()
secureTaskSwitcher = SecureTaskSwitcher()

return true
}

Expand Down
70 changes: 70 additions & 0 deletions SMSecureTaskSwitcher/Classes/SecureTaskSwitcher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// SecureTaskSwitcher.swift
// SMSecureTaskSwitcher
//
// Created by Miroslaw Stanek on 25/10/2021.
//

import Foundation
import UIKit

public class SecureTaskSwitcher {

let secureWindow: UIWindow
let notificationCenter: NotificationCenter
let mainScreen: UIScreen
let configuration: SMSecureTaskSwitcherConfiguration

public init(configuration: SMSecureTaskSwitcherConfiguration = SMSecureTaskSwitcherBlurredConfiguration(),
notificationCenter: NotificationCenter = NotificationCenter.default,
mainScreen: UIScreen = UIScreen.main) {
self.notificationCenter = notificationCenter
self.mainScreen = mainScreen
self.configuration = configuration

self.secureWindow = UIWindow.init(frame: self.mainScreen.bounds)
self.secureWindow.windowLevel = UIWindow.Level.alert + 10
self.secureWindow.backgroundColor = UIColor.clear
self.secureWindow.isHidden = true

self.secureWindow.rootViewController = securedViewController()

setupObservers()
}

private func securedViewController() -> UIViewController {
let rootViewController: UIViewController = UIViewController()
rootViewController.view.backgroundColor = UIColor.clear
return rootViewController
}

private func setupObservers() {
self.notificationCenter.addObserver(self,
selector: #selector(applicationWillEnterForeground),
name: UIApplication.willEnterForegroundNotification,
object: nil)
}

public func applicationDidEnterBackground() {
self.updateSecureView()
self.secureWindow.isHidden = false
}

@objc
public func applicationWillEnterForeground() {
self.secureWindow.isHidden = true
}

private func updateSecureView() {
if let view = self.secureWindow.rootViewController?.view {
for (_, subview) in view.subviews.enumerated() {
subview.removeFromSuperview()
}
}

self.secureWindow.rootViewController?.view
.addSubview(self.configuration.secureView(forFrame: self.mainScreen.bounds))
}
}