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
2 changes: 0 additions & 2 deletions example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>13.0</string>
</dict>
</plist>
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
image_cropper: 64567491beea6cd1bc4b11948e2babb590de5826
image_picker_ios: e0ece4aa2a75771a7de3fa735d26d90817041326
screen_protector: 18c6aca2dc5d2a832f6787a5318f97f03e9d3150
image_cropper: b8ef14d3fcff4040b0f9da2ca28d98219a5cba0e
image_picker_ios: 4f2f91b01abdb52842a8e277617df877e40f905b
screen_protector: 585e4a9744efa35ec4ba9a6877b22e46b8d48987
ScreenProtectorKit: 6ceb3e0808341a9bc15d175bff40dfdd4b32da71
TOCropViewController: 797deaf39c90e6e9ddd848d88817f6b9a8a09888

Expand Down
19 changes: 0 additions & 19 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,4 @@ import Flutter

@main
@objc class AppDelegate: FlutterAppDelegate {
var flutterEngine: FlutterEngine?

override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
self.flutterEngine = FlutterEngine(name: "my_engine")
self.flutterEngine?.run()
GeneratedPluginRegistrant.register(with: self.flutterEngine!)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

override func applicationDidEnterBackground(_ application: UIApplication) {
var bgTask: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier(rawValue: 0)
bgTask = application.beginBackgroundTask {
application.endBackgroundTask(bgTask)
bgTask = UIBackgroundTaskIdentifier.invalid
}
}
}
4 changes: 4 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string>UIWindowScene</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
Expand Down
40 changes: 27 additions & 13 deletions example/ios/Runner/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,42 @@
import UIKit
import Flutter

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?

func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {

guard let windowScene = (scene as? UIWindowScene) else { return }

let appDelegate = UIApplication.shared.delegate as! AppDelegate
guard let flutterEngine = appDelegate.flutterEngine else { return }

class SceneDelegate: FlutterSceneDelegate {
let flutterEngine = FlutterEngine(name: "my_engine")

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

flutterEngine.run()
GeneratedPluginRegistrant.register(with: flutterEngine)
self.registerSceneLifeCycle(with: flutterEngine)

let flutterViewController = FlutterViewController(
engine: flutterEngine,
nibName: nil,
bundle: nil
)

let window = UIWindow(windowScene: windowScene)
window.rootViewController = flutterViewController
self.window = window
window.makeKeyAndVisible()

super.scene(scene, willConnectTo: session, options: connectionOptions)
}

override func sceneDidEnterBackground(_ scene: UIScene) {
let application = UIApplication.shared
var bgTask: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier(rawValue: 0)
bgTask = application.beginBackgroundTask {
application.endBackgroundTask(bgTask)
bgTask = UIBackgroundTaskIdentifier.invalid
}
super.sceneDidEnterBackground(scene)
}
}

24 changes: 12 additions & 12 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
url: "https://pub.dev"
source: hosted
version: "1.4.0"
version: "1.4.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -268,26 +268,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
url: "https://pub.dev"
source: hosted
version: "0.12.17"
version: "0.12.19"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.13.0"
meta:
dependency: transitive
description:
name: meta
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
url: "https://pub.dev"
source: hosted
version: "1.16.0"
version: "1.17.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -369,10 +369,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
url: "https://pub.dev"
source: hosted
version: "0.7.6"
version: "0.7.10"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -406,5 +406,5 @@ packages:
source: hosted
version: "1.1.1"
sdks:
dart: ">=3.9.0 <4.0.0"
flutter: ">=3.35.0"
dart: ">=3.10.0 <4.0.0"
flutter: ">=3.38.0"
3 changes: 2 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ description: Demonstrates how to use the screen_protector plugin.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

environment:
sdk: ">=2.18.1 <4.0.0"
sdk: "^3.10.0"
flutter: ">=3.38.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
10 changes: 8 additions & 2 deletions ios/Classes/FlutterRootViewResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ final class FlutterRootViewResolver: ScreenProtectorRootViewResolving {
return nil
}

guard let flutterVC = windowScene.windows
.first(where: { $0.isKeyWindow })?
let keyWindow: UIWindow?
if #available(iOS 15.0, *) {
keyWindow = windowScene.keyWindow
} else {
keyWindow = windowScene.windows.first(where: { $0.isKeyWindow })
}

guard let flutterVC = keyWindow?
.rootViewController as? FlutterViewController else {
log("resolveFlutterRootView: FlutterViewController not found on key window")
return nil
Expand Down
20 changes: 18 additions & 2 deletions ios/Classes/SwiftScreenProtectorPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum ScrennProtectorMethod: String {
case isRecording
}

public class SwiftScreenProtectorPlugin: NSObject, FlutterPlugin {
public class SwiftScreenProtectorPlugin: NSObject, FlutterPlugin, FlutterSceneLifeCycleDelegate {
private static var channel: FlutterMethodChannel? = nil
private let protectKit: ScreenProtectorKit
private var protectMode: ScreenProtectorMode = .none
Expand All @@ -39,6 +39,7 @@ public class SwiftScreenProtectorPlugin: NSObject, FlutterPlugin {

registrar.addMethodCallDelegate(instance, channel: SwiftScreenProtectorPlugin.channel!)
registrar.addApplicationDelegate(instance)
registrar.addSceneDelegate(instance)
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
Expand All @@ -62,6 +63,16 @@ public class SwiftScreenProtectorPlugin: NSObject, FlutterPlugin {
clearDataLeakageProtection()
}

public func sceneWillResignActive(_ scene: UIScene) {
updateWindowIfNeeded()
applyDataLeakageProtection()
}

public func sceneDidBecomeActive(_ scene: UIScene) {
updateWindowIfNeeded()
clearDataLeakageProtection()
}

deinit {
updateWindowIfNeeded()
protectKit.removeAllObserver()
Expand Down Expand Up @@ -205,7 +216,12 @@ private extension SwiftScreenProtectorPlugin {
}

static func keyWindow() -> UIWindow? {
if #available(iOS 13.0, *) {
if #available(iOS 15.0, *) {
return UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.compactMap { $0.keyWindow }
.first
} else if #available(iOS 13.0, *) {
return UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.flatMap { $0.windows }
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version: 1.5.1
homepage: https://github.com/prongbang/screen_protector

environment:
sdk: ">=2.12.0 <4.0.0"
flutter: ">=2.5.0"
sdk: "^3.10.0"
flutter: ">=3.38.0"

dependencies:
flutter:
Expand Down
Loading