How to disable screen recording in iOS app programmatically
Published November 20, 2020In this post, we will learn How to disable Screen Recording in iOS application programmatically.
- Create an ios Application
- Add object C files to the created project.
- By using the notification add observer methods we can trigger the screen recording status
ScreenRecordingDetector.h
// /* #import <Foundation/Foundation.h> extern NSString *kScreenRecordingDetectorRecordingStatusChangedNotification; @interface ScreenRecordingDetector : NSObject +(instancetype)sharedInstance; @end |
ScreenRecordingDetector.m
// #import "ScreenRecordingDetector.h" @interface ScreenRecordingDetector() @property BOOL lastRecordingState; @end
ScreenRecordingDetector *detector = [ScreenRecordingDetector sharedInstance]; |
NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive), name:UIApplication.didBecomeActiveNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillResignActive), name:UIApplication.willResignActiveNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(screenCaptureStatusChanged), name: NSNotification.Name.screenRecordingDetectorRecordingStatusChanged, object: nil)
@objc func appDidBecomeActive (){ ScreenRecordingDetector.triggerDetectorTimer() print("become active")
if (ScreenRecordingDetector.sharedInstance().isRecording()) {
print("Recording started")
} } @objc func applicationWillResignActive () { ScreenRecordingDetector.stopTimer()
print("Resign active") }
@objc func screenCaptureStatusChanged () { setupView()
print("screencaptured active")
} //MARK:Recording SetUp
func setupView() {
if (ScreenRecordingDetector.sharedInstance().isRecording()) {
print("Recording started")
}
if (ScreenRecordingDetector.sharedInstance().isRecording() == true) { print("Recording already exists")
}
else { print("Recording not started") } }
|
Find Example code at https://github.com/rrtutors/ScreenRecording-ios
How to take a screenshot in Ios Programmatically
How to Make a Phone call in Ios-10 Using Swift
Article Contributed By :
|
|
|
|
2753 Views |