prongbang / ScreenProtectorKit

Safe Data Leakage via Application Background Screenshot and Prevent Screenshot for iOS.
MIT License
27 stars 6 forks source link

Obj-C integration example ? #4

Open vptcnt opened 1 year ago

vptcnt commented 1 year ago

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 commented 2 weeks ago

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];