-
Notifications
You must be signed in to change notification settings - Fork 2
/
AppDelegate.swift
89 lines (72 loc) · 2.43 KB
/
AppDelegate.swift
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
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
weak var screen : UIView? = nil
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
self.listenToTakeScreenshot();
self.listenToTakeScreenRecording();
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func applicationWillResignActive(
_ application: UIApplication
) {
blurScreen()
}
override func applicationDidBecomeActive(
_ application: UIApplication
) {
removeBlurScreen()
}
private func listenToTakeScreenRecording() {
if #available(iOS 11.0, *) {
NotificationCenter.default.addObserver(
forName: UIScreen.capturedDidChangeNotification,
object: nil,
queue: .main) { notification in
DispatchQueue.main.async {
if self.window?.isHidden == false{
self.hideScreen()
}
}
}
} else {
}
}
private func listenToTakeScreenshot() {
NotificationCenter.default.addObserver(
forName: UIApplication.userDidTakeScreenshotNotification,
object: nil,
queue: .main) { notification in
if self.window?.isHidden == false{
self.blurScreen();
}
}
}
private func hideScreen() {
if #available(iOS 11.0, *) {
if UIScreen.main.isCaptured {
self.blurScreen();
} else {
self.removeBlurScreen();
}
} else {
// Fallback on earlier versions
}
}
func blurScreen(style: UIBlurEffect.Style = UIBlurEffect.Style.regular) {
screen = UIScreen.main.snapshotView(afterScreenUpdates: false)
let blurEffect = UIBlurEffect(style: style)
let blurBackground = UIVisualEffectView(effect: blurEffect)
screen?.addSubview(blurBackground)
blurBackground.frame = (screen?.frame)!
window?.addSubview(screen!)
}
func removeBlurScreen() {
screen?.removeFromSuperview()
}
}