Skip to content

Commit

Permalink
Fix code to hide view properly in iOS and to do check one app resume …
Browse files Browse the repository at this point in the history
…from background
  • Loading branch information
agmv committed Nov 8, 2016
1 parent 2111c2b commit 348cce9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
17 changes: 15 additions & 2 deletions src/android/secureDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,29 @@

public class secureDevice extends CordovaPlugin {

CordovaInterface cordova;
CordovaWebView view;

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
this.cordova = cordova;
this.view = webView;
checkDevice();
}

@Override
public void onResume(boolean multiTasking) {
checkDevice();
}

private void checkDevice() {
boolean _isDeviceRooted = isDeviceRooted();
boolean _isPasscodeSet = doesDeviceHaveSecuritySetup(cordova.getActivity());
boolean _isPasscodeSet = doesDeviceHaveSecuritySetup(this.cordova.getActivity());

if (_isDeviceRooted || !_isPasscodeSet) {
// Remove View
View v = webView.getView();
View v = this.view.getView();
ViewGroup viewParent = (ViewGroup) v.getParent();
viewParent.removeView(v);

Expand Down
40 changes: 25 additions & 15 deletions src/ios/secureDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,34 @@ @implementation secureDevice

- (void)pluginInitialize
{
BOOL jailbroken = [UIDevice currentDevice].isJailBroken;
LNPasscodeStatus status = [UIDevice currentDevice].passcodeStatus;

if (jailbroken || status == LNPasscodeStatusDisabled || status == LNPasscodeStatusUnknown) {
//Remove webView
[self.webView removeFromSuperview];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume:)
name:UIApplicationDidBecomeActiveNotification object:nil];
[self checkDevice];
}

//Show alert dialog and close app
NSBundle *thisBundle = [NSBundle bundleWithPath: [[NSBundle mainBundle] pathForResource:NSStringFromClass([self class]) ofType: @"bundle"]];
NSString *alertMessage = [thisBundle localizedStringForKey:@"This application does not run on a device that is jailbroken or does not have a passcode set." value:nil table:nil];
NSString *alertCloseButtonText = [thisBundle localizedStringForKey:@"Close" value:nil table:nil];

dispatch_async( dispatch_get_main_queue(), ^ {
[self showAlert:alertMessage closeLabel:alertCloseButtonText];
});
}
- (void) onResume:(UIApplication *)application
{
[self checkDevice];
}

- (void) checkDevice
{
BOOL jailbroken = [UIDevice currentDevice].isJailBroken;
LNPasscodeStatus status = [UIDevice currentDevice].passcodeStatus;

if (jailbroken || status == LNPasscodeStatusDisabled || status == LNPasscodeStatusUnknown) {
NSBundle *thisBundle = [NSBundle bundleWithPath: [[NSBundle mainBundle] pathForResource:NSStringFromClass([self class]) ofType: @"bundle"]];
NSString *alertMessage = [thisBundle localizedStringForKey:@"This application does not run on a device that is jailbroken or does not have a passcode set." value:nil table:nil];
NSString *alertCloseButtonText = [thisBundle localizedStringForKey:@"Close" value:nil table:nil];

dispatch_async( dispatch_get_main_queue(), ^ {
//Remove webView
[self.webView removeFromSuperview];
// Show Alert
[self showAlert:alertMessage closeLabel:alertCloseButtonText];
});
}
}
/*
* showAlert - Common method to instantiate the alert view for alert
* Parameters:
Expand Down

0 comments on commit 348cce9

Please sign in to comment.