Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): added event to detect that screenshot was taken #11665

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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