-
-
Save androidmads/ab90da83936c074e28f4a15d38db2719 to your computer and use it in GitHub Desktop.
Get notified when user takes screenshot on Xamarin.iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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