Skip to content

Instantly share code, notes, and snippets.

@jmptrader
Forked from dannycabrera/AppDelegate.cs
Created July 7, 2020 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmptrader/d9073480826d03d5c6a96bed36204207 to your computer and use it in GitHub Desktop.
Save jmptrader/d9073480826d03d5c6a96bed36204207 to your computer and use it in GitHub Desktop.
Get notified when user takes screenshot on Xamarin.iOS
using Foundation;
using UIKit;
namespace YourApp
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
NSObject _screenshotNotification = null;
public override void OnActivated (UIApplication application)
{
try {
// Start observing screenshot notification
if (_screenshotNotification == null) {
_screenshotNotification = NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.UserDidTakeScreenshotNotification,
(NSNotification n) => {
Console.WriteLine("UserDidTakeScreenshotNotification");
n.Dispose ();
}
);
}
} catch (Exception ex) {
//Do something
}
}
public override void OnResignActivation (UIApplication application)
{
try {
// Stop observer
if (_screenshotNotification != null) {
NSNotificationCenter.DefaultCenter.RemoveObserver (_screenshotNotification);
_screenshotNotification.Dispose ();
_screenshotNotification = null;
}
} catch (Exception ex) {
//Do something
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment