I worked on an app where securing chat content was a requirement. After R&D, I concluded that preventing screen capture in an iOS app is not directly supported by the iOS operating system. However, we can customize our code to achieve the desired result.
As a solution, I created ScreenShield, an iOS library designed to secure content by blocking screenshots and screen recordings. It provides a simple solution to protect your app's content. I hope it proves helpful for others facing the same challenge.
ScreenShield for ios UIKit/SwiftUI
HOW TO USE:
Add the following line to your Podfile and run pod install:
pod 'ScreenShield'
UIKIT EXAMPLE:
import UIKit
import ScreenShield
class ViewController: UIViewController {
override func viewDidAppear() {
super.viewDidAppear()
// Protect ScreenShot
ScreenShield.shared.protect(view: self.view)
// Protect Screen-Recording
ScreenShield.shared.protectFromScreenRecording()
}
}
SWIFTUI EXAMPLE:
import SwiftUI
import ScreenShield
struct ContentView: View {
var body: some View {
Text("Hello, World!")
.protectScreenshot() // Protect the view
.onAppear {
ScreenShield.shared.protectFromScreenRecording() // Protect Screen-Recording
}
}
}