Skip to content

screen_protector plugin not work with flutter Apps that have SceneDelegate and AppDelegate #43

@MohamedElgamal93

Description

@MohamedElgamal93

screen_protector plugin
not work with flutter that have SceneDelegate please need you support

//Marker SceneDelegate
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 }
    
    let flutterViewController = FlutterViewController(engine: flutterEngine,
                                                      nibName: nil,
                                                      bundle: nil)
    
    let window = UIWindow(windowScene: windowScene)
    window.rootViewController = flutterViewController
    self.window = window
    window.makeKeyAndVisible()
}

}

//Marker info.plist
UIApplicationSceneManifest

UIApplicationSupportsMultipleScenes

UISceneConfigurations

UIWindowSceneSessionRoleApplication


UISceneConfigurationName
Default Configuration
UISceneDelegateClassName
$(PRODUCT_MODULE_NAME).SceneDelegate



//Marker AppDelegate

import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
var flutterEngine: FlutterEngine?
// MARK: - App Lifecycle
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
    }
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions