TheDeveloper
TheDeveloper

Reputation: 1217

Xamarin iOS: Disable screenshot option

I am working on an app which has very sensitive data, which we do not want to be saved anywhere. In Android we can disable taking screenshot. Is there a way to do the same on iOS? I do not want any user who access sensitive information to try to take screenshot.

PS. i am using xamarin forms to create the app, but if this functionality can be achieved through objective C/ swift, they can always be achieved through xamarin.

Upvotes: 2

Views: 3772

Answers (2)

Luke Pothier
Luke Pothier

Reputation: 1030

You cannot prevent users from taking screenshots on iOS. However, since your concerns are security related, one thing you might want to consider is preventing the OS from displaying a screenshot of your app in the recently used apps list when users have the app minimised, which can be done. To do so (using Xamarin), you need to override OnResignActivation and OnActivated in your AppDelegate:

// Hide app state in recently used apps list
public override void OnResignActivation(UIApplication application)
{
    var view = new UIView(Window.Frame)
    {
        Tag = new nint(101),
        BackgroundColor = UIColor.White
    }
    Window.AddSubview(view);
    Window.BringSubviewToFront(view);
}

// Remove window hiding app content when app is resumed
public override void OnActivated(UIApplication application)
{
    var view = Window.ViewWithTag(new nint(101));
    view?.RemoveFromSuperview();
}

I realise this doesn't answer your question, but it may be as much as can be done.

Upvotes: 6

Geoherna
Geoherna

Reputation: 3574

There is really no way you can prevent a user from taking a screenshot, it is simply not allowed in iOS. What you could do, however, is perform actions when you are able to detect a screenshot was taken.

This is probably as good as it gets. I don't have a Xamarin solution, this is how you would do it in Swift: https://stackoverflow.com/a/18158483/4660602

The user provides an answer for both Obj-c and Swift, so you if you can port that code over to Xamarin successfully, you can perform some intuitive actions after a screenshot is taken, because you cannot prevent the user from taking one.

Upvotes: 2

Related Questions