Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obj-C integration example ? #4

Open
vptcnt opened this issue Nov 30, 2022 · 1 comment
Open

Obj-C integration example ? #4

vptcnt opened this issue Nov 30, 2022 · 1 comment

Comments

@vptcnt
Copy link

vptcnt commented Nov 30, 2022

Hello,

Do you know how to implement your library in an Ios written in Obj-C ?

Thanks for your help

# SWIFT 
import ScreenProtectorKit

class AppDelegate: FlutterAppDelegate {

    private lazy var screenProtectorKit = { return ScreenProtectorKit(window: window) }()

    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
    
        screenProtectorKit.configurePreventionScreenshot()
  
        return true
    }

    override func applicationDidBecomeActive(_ application: UIApplication) {
        screenProtectorKit.enabledPreventScreenshot()
    }

    override func applicationWillResignActive(_ application: UIApplication) {
        screenProtectorKit.disablePreventScreenshot()
    }
    
}

# OBJ-C ?
@GManShen
Copy link

GManShen commented Oct 30, 2024

You shouldnt be using this to begin with, this is not the correct way to detect screenshots, this may break your UI, if not now, then in further releases of iOS, but for the sake of information, you can create a swift file which will import the ScreenProtectorKit swift file and expose functions to objc.

import UIKit
import ScreenProtectorKit

@objc public class ScreenProtectorBridge: NSObject {

private var protectorKit: ScreenProtectorKit?

@objc public static let shared = ScreenProtectorBridge()

private override init() {
    super.init()
}

@objc public func setup(window: UIWindow?) {
    protectorKit = ScreenProtectorKit(window: window)
}

@objc public func configurePreventionScreenshot() {
    protectorKit?.configurePreventionScreenshot()
}

@objc public func enablePreventScreenshot() {
    protectorKit?.enabledPreventScreenshot()
}

@objc public func disablePreventScreenshot() {
    protectorKit?.disablePreventScreenshot()
}

@objc public func enableBlurScreen(style: UIBlurEffect.Style = .light) {
    protectorKit?.enabledBlurScreen(style: style)
}

@objc public func disableBlurScreen() {
    protectorKit?.disableBlurScreen()
}

@objc public func enableColorScreen(hexColor: String) {
    protectorKit?.enabledColorScreen(hexColor: hexColor)
}

@objc public func disableColorScreen() {
    protectorKit?.disableColorScreen()
}

@objc public func enableImageScreen(named: String) {
    protectorKit?.enabledImageScreen(named: named)
}

@objc public func disableImageScreen() {
    protectorKit?.disableImageScreen()
}

@objc public func removeAllObserver() {
    protectorKit?.removeAllObserver()
}

@objc public func observeScreenshot(callback: @escaping () -> Void) {
    protectorKit?.screenshotObserver(using: callback)
}

@available(iOS 11.0, *)
@objc public func observeScreenRecord(callback: @escaping (Bool) -> Void) {
    protectorKit?.screenRecordObserver(using: callback)
}

@available(iOS 11.0, *)
@objc public func isScreenRecording() -> Bool {
    return protectorKit?.screenIsRecording() ?? false
}

}

then in objective c controller use
#import "MyApp-Swift.h"

and use like this
[[ScreenProtectorBridge shared] setupWithWindow:self.window];
[[ScreenProtectorBridge shared] configurePreventionScreenshot];
[[ScreenProtectorBridge shared] enablePreventScreenshot];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants