leonkuehn
leonkuehn

Reputation: 124

iOS detect Screenshot if App is in background

I'm new in Xcode and Objective-C, so I need your help.
I wan't to have an app which detect an Screenshot if this App is in the Background, for example you pressed the home button, so you be on the Home Screen, if you take a screenshot now I want that the app show an alert on the Home Screen. I try this:

in my AppDelegate.m

- (void)applicationDidEnterBackground:(UIApplication *)application {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidTakeScreenshot:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}

- (void)userDidTakeScreenshot:(NSNotification *)notification{
    NSLog(@"screenshot detected");

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"screenshot detected" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"nil];
    [alert show];
}

But if the App enter the background and then i take a screenshot the alert don't show. I hope you will understand my problem.

And I excuse for my english.

Upvotes: 1

Views: 1837

Answers (2)

michaelxing
michaelxing

Reputation: 93

"UIApplicationUserDidTakeScreenshotNotification" : I think there is no way to detect screenshot When your App in Background or suspend. This notification only be notify when your App in foreground.

Upvotes: 0

rckoenes
rckoenes

Reputation: 69469

UIAlert will only work if you app is in the foreground, you might be able to get the user attention with an UILocalNotification.

Also only if your is really running in the background will you be able to detect the screenshot. So you app should be VOIP, Stream audio, accessory app, etc..

Default you app will not run in the background.

Upvotes: 2

Related Questions