Skip to content

Instantly share code, notes, and snippets.

@dannycabrera
Created November 2, 2016 12:51
Show Gist options
  • Save dannycabrera/b83bb0eac343284521516122157c0335 to your computer and use it in GitHub Desktop.
Save dannycabrera/b83bb0eac343284521516122157c0335 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