Hello SO users since i started my career in swift and my current project is in objective c i need to convert my swift code into objective c .
I've requirement to disable taking screenshot in iOS device. since Apple not giving support for that, another workaround Im trying is - get notified when screenshot is taken using UIApplicationUserDidTakeScreenshotNotification and get last photo from photo gallery and delete it as below code in swift.
func deleteAppScreenShot() {
NSLog("i am here")
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors?[0] = Foundation.NSSortDescriptor(key: "creationDate", ascending: true)
let fetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: fetchOptions)
guard let lastAsset = fetchResult.lastObject else { return }
PHPhotoLibrary.shared().performChanges {
PHAssetChangeRequest.deleteAssets([lastAsset] as NSFastEnumeration)
} completionHandler: { (success, errorMessage) in
if !success, let errorMessage = errorMessage {
print(errorMessage.localizedDescription)
}
}
}
However the above approach is not the desired solution as it will always ask the user permission to delete the last photo
Can someone kindly tell how to disable the screenshot in iOS ?