Search code examples
objective-cxcodeblockscreenshotdetect

Xcode Objective-C ShotBlocker: How to detect and block screenshots


In an app I'm creating, you're not allowed to take screenshots. I was wondering how you could detect and block screenshots. I found out you could do that using ShotBlocker, but I don't know how. Does anyone know how you can detect and block screenshots in Objective-C?


Solution

  • There is no way to block a screenshot on iOS. At least you can detect the screenshot after it was taken in that way:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenshotDetected) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
    
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil];
    }
    
    - (void)screenshotDetected {
    
        UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Hey!"
                                                         message:@"You're not allowed to do that"
                                                        delegate:self
                                               cancelButtonTitle:@"Cancel"
                                               otherButtonTitles: nil];
        [alert addButtonWithTitle:@"GO"];
        [alert show];
    }