From e2426bcb3ee3af07b9e0cb8df10ed7d261b77bd8 Mon Sep 17 00:00:00 2001 From: Nick Adriaenssens Date: Tue, 12 Jul 2016 10:21:43 +0200 Subject: [PATCH] Added functionality to enable or disable the privacyScreen --- plugin.xml | 37 ++++++++++++++++++++--------------- src/ios/PrivacyScreenPlugin.h | 9 ++++++++- src/ios/PrivacyScreenPlugin.m | 23 ++++++++++++++++++++++ www/PrivacyScreenPlugin.js | 18 +++++++++-------- 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/plugin.xml b/plugin.xml index 99d0576..ed0fb08 100644 --- a/plugin.xml +++ b/plugin.xml @@ -4,28 +4,33 @@ PrivacyScreenPlugin Secures your app from displaying a screenshot in task switchers under Android and iOS. Keeps sensitive information private. MIT - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + diff --git a/src/ios/PrivacyScreenPlugin.h b/src/ios/PrivacyScreenPlugin.h index 6ce5c3a..7684ede 100644 --- a/src/ios/PrivacyScreenPlugin.h +++ b/src/ios/PrivacyScreenPlugin.h @@ -18,6 +18,13 @@ typedef struct { } CDV_iOSDevice; -@interface PrivacyScreenPlugin : CDVPlugin +@interface PrivacyScreenPlugin : CDVPlugin { + @protected + BOOL _privacyScreenEnabled; +} + +@property (readwrite, assign) BOOL privacyScreenEnabled; + +- (void)enabled:(CDVInvokedUrlCommand*)command; @end \ No newline at end of file diff --git a/src/ios/PrivacyScreenPlugin.m b/src/ios/PrivacyScreenPlugin.m index 421114d..02227ce 100644 --- a/src/ios/PrivacyScreenPlugin.m +++ b/src/ios/PrivacyScreenPlugin.m @@ -10,8 +10,17 @@ @implementation PrivacyScreenPlugin +- (id)settingForKey:(NSString*)key +{ + return [self.commandDelegate.settings objectForKey:[key lowercaseString]]; +} + - (void)pluginInitialize { + if ([self settingForKey:@"PrivacyScreenEnabled"]) { + self.privacyScreenEnabled = [(NSNumber*)[self settingForKey:@"PrivacyScreenEnabled"] boolValue]; + } + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; @@ -30,6 +39,10 @@ - (void)onAppDidBecomeActive:(UIApplication *)application - (void)onAppWillResignActive:(UIApplication *)application { + if (!_privacyScreenEnabled) { + return; + } + CDVViewController *vc = (CDVViewController*)self.viewController; NSString *imgName = [self getImageName:self.viewController.interfaceOrientation delegate:(id)vc device:[self getCurrentDevice]]; UIImage *splash = [UIImage imageNamed:imgName]; @@ -151,4 +164,14 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i return imageName; } +- (void)enabled:(CDVInvokedUrlCommand*)command +{ + id value = [command.arguments objectAtIndex:0]; + if (!([value isKindOfClass:[NSNumber class]])) { + value = [NSNumber numberWithBool:NO]; + } + + self.privacyScreenEnabled = [value boolValue]; +} + @end \ No newline at end of file diff --git a/www/PrivacyScreenPlugin.js b/www/PrivacyScreenPlugin.js index ae80e7d..5ba3e84 100644 --- a/www/PrivacyScreenPlugin.js +++ b/www/PrivacyScreenPlugin.js @@ -1,8 +1,10 @@ -//var exec = require('cordova/exec'); - -/** - * Not sure this will even have a JS API - */ -//exports.activate = function(arg, success, error) { - //exec(success, error, "PrivacyScreenPlugin", "activate", [arg]); -//}; +var exec = require('cordova/exec'); + + +var PrivacyScreen = function () {}; + +PrivacyScreen.enabled = function(enabled) { + exec(null, null, "PrivacyScreenPlugin", "enabled", [enabled]); +}; + +module.exports = PrivacyScreen; \ No newline at end of file