forked from yankodimitrov/SwiftPasscodeLock
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathCustomPasscodeLockPresenter.swift
More file actions
103 lines (76 loc) · 2.98 KB
/
CustomPasscodeLockPresenter.swift
File metadata and controls
103 lines (76 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// CustomPasscodeLockPresenter.swift
// PasscodeLock
//
// Created by Chris Ziogas on 19/12/15.
// Copyright © 2015 Yanko Dimitrov. All rights reserved.
//
import Foundation
import PasscodeLock
class CustomPasscodeLockPresenter: PasscodeLockPresenter {
private let notificationCenter: NSNotificationCenter
private let splashView: UIView
var isFreshAppLaunch = true
init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType) {
notificationCenter = NSNotificationCenter.defaultCenter()
splashView = LockSplashView()
// TIP: you can set your custom viewController that has added functionality in a custom .xib too
let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode(allowCancellation: true), configuration: configuration)
super.init(mainWindow: window, configuration: configuration, viewController: passcodeLockVC)
// add notifications observers
notificationCenter.addObserver(
self,
selector: "applicationDidLaunched",
name: UIApplicationDidFinishLaunchingNotification,
object: nil
)
notificationCenter.addObserver(
self,
selector: "applicationDidEnterBackground",
name: UIApplicationDidEnterBackgroundNotification,
object: nil
)
notificationCenter.addObserver(
self,
selector: "applicationDidBecomeActive",
name: UIApplicationDidBecomeActiveNotification,
object: nil
)
}
deinit {
// remove all notfication observers
notificationCenter.removeObserver(self)
}
dynamic func applicationDidLaunched() -> Void {
// start the Pin Lock presenter
passcodeLockVC.successCallback = { [weak self] _ in
// we can set isFreshAppLaunch to false
self?.isFreshAppLaunch = false
}
presentPasscodeLock()
}
dynamic func applicationDidEnterBackground() -> Void {
// present PIN lock
presentPasscodeLock()
// add splashView for iOS app background swithcer
addSplashView()
}
dynamic func applicationDidBecomeActive() -> Void {
// remove splashView for iOS app background swithcer
removeSplashView()
}
private func addSplashView() {
// add splashView for iOS app background swithcer
if isPasscodePresented {
passcodeLockVC.view.addSubview(splashView)
} else {
if let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate {
appDelegate.window?.addSubview(splashView)
}
}
}
private func removeSplashView() {
// remove splashView for iOS app background swithcer
splashView.removeFromSuperview()
}
}