From b9df3399d9aa41b34a8d38f1dad96bca20ff9de2 Mon Sep 17 00:00:00 2001 From: Vijay Vikram Singh Date: Thu, 30 Apr 2020 10:54:33 -0700 Subject: [PATCH] feat(ios): added event to detect that screenshot was taken (#11665) Fixes TIMOB-27853 --- apidoc/Titanium/App/iOS/iOS.yml | 5 +++++ iphone/Classes/TiAppiOSProxy.m | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/apidoc/Titanium/App/iOS/iOS.yml b/apidoc/Titanium/App/iOS/iOS.yml index e5c07ec382b..d02391e9347 100644 --- a/apidoc/Titanium/App/iOS/iOS.yml +++ b/apidoc/Titanium/App/iOS/iOS.yml @@ -1395,6 +1395,11 @@ events: platforms: [iphone, ipad] since: "8.2.0" + - name: screenshotcaptured + summary: Fired after the user takes a screenshot, e.g. by pressing both the home and lock screen buttons. + platforms: [iphone, ipad] + since: "9.1.0" + --- name: NotificationParams summary: | diff --git a/iphone/Classes/TiAppiOSProxy.m b/iphone/Classes/TiAppiOSProxy.m index 5479aef0c25..1356fa37592 100644 --- a/iphone/Classes/TiAppiOSProxy.m +++ b/iphone/Classes/TiAppiOSProxy.m @@ -133,6 +133,13 @@ - (void)_listenerAdded:(NSString *)type count:(int)count name:kTiTraitCollectionChanged object:nil]; } + + if ((count == 1) && [type isEqual:@"screenshotcaptured"]) { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didTakeScreenshot:) + name:UIApplicationUserDidTakeScreenshotNotification + object:nil]; + } } - (void)_listenerRemoved:(NSString *)type count:(int)count @@ -189,6 +196,9 @@ - (void)_listenerRemoved:(NSString *)type count:(int)count if ((count == 1) && [type isEqual:@"traitcollectionchange"]) { [[NSNotificationCenter defaultCenter] removeObserver:self name:kTiTraitCollectionChanged object:nil]; } + if ((count == 1) && [type isEqual:@"screenshotcaptured"]) { + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil]; + } } #pragma mark Public @@ -205,6 +215,11 @@ - (void)didChangeTraitCollection:(NSNotification *)info [self fireEvent:@"traitcollectionchange"]; } +- (void)didTakeScreenshot:(NSNotification *)info +{ + [self fireEvent:@"screenshotcaptured"]; +} + - (void)didReceiveApplicationShortcutNotification:(NSNotification *)info { NSMutableDictionary *event = [[NSMutableDictionary alloc] initWithDictionary:@{