Skip to content

Commit

Permalink
feat(ios): added event to detect that screenshot was taken (#11665)
Browse files Browse the repository at this point in the history
Fixes TIMOB-27853
  • Loading branch information
vijaysingh-axway committed Apr 30, 2020
1 parent e2fce1d commit b9df339
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apidoc/Titanium/App/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
15 changes: 15 additions & 0 deletions iphone/Classes/TiAppiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:@{
Expand Down

0 comments on commit b9df339

Please sign in to comment.