Skip to content

Commit

Permalink
Default timer fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MobilityTiago committed Mar 27, 2017
1 parent cdf05a9 commit 20c451b
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/ios/PrivacyScreenPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ @implementation PrivacyScreenPlugin
- (void)pluginInitialize
{
NSString* privacyTimerKey = @"privacytimer";
NSString* prefTimer = [self.commandDelegate.settings objectForKey:[privacyTimerKey lowercaseString]];\
NSString* prefTimer = [self.commandDelegate.settings objectForKey:[privacyTimerKey lowercaseString]];
//Default value
self.privacyTimerInterval = PRIVACY_TIMER_DEFAULT;
if(prefTimer)
self.privacyTimerInterval = [prefTimer floatValue] > 0.0f ? [prefTimer floatValue] : PRIVACY_TIMER_DEFAULT;
self.privacyTimerInterval = [prefTimer floatValue] > 0.0f ? [prefTimer floatValue] : PRIVACY_TIMER_DEFAULT;


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil];
Expand All @@ -35,11 +38,11 @@ - (void)pluginInitialize
NSString* onBackgroundKey = @"privacyonbackground";

if([self.commandDelegate.settings objectForKey:[onBackgroundKey lowercaseString]] && [[self.commandDelegate.settings objectForKey:[onBackgroundKey lowercaseString]] isEqualToString:@"true"])
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
else
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil];
}

#pragma mark - Explicit Commands
Expand Down Expand Up @@ -67,7 +70,7 @@ - (void) setTimer:(CDVInvokedUrlCommand*)command

- (void) hidePrivacyScreen:(CDVInvokedUrlCommand*)command
{
[self removePrivacyScreen];
[self removePrivacyScreen];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
Expand Down Expand Up @@ -95,7 +98,7 @@ - (void)onAppDidBecomeActive:(UIApplication *)application
{
//[self.privacyTimer invalidate];
if(!self.privacyTimer)
self.privacyTimer = [NSTimer scheduledTimerWithTimeInterval:self.privacyTimerInterval
self.privacyTimer = [NSTimer scheduledTimerWithTimeInterval:self.privacyTimerInterval
target:self
selector:@selector(removePrivacyScreen)
userInfo:nil
Expand Down Expand Up @@ -238,10 +241,10 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
switch (currentOrientation) {
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
imageName = [imageName stringByAppendingString:@"-Landscape"];
break;
imageName = [imageName stringByAppendingString:@"-Landscape"];
break;
default:
break;
break;
}
}
imageName = [imageName stringByAppendingString:@"-736h"];
Expand All @@ -253,21 +256,21 @@ - (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(i
switch (currentOrientation) {
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
imageName = [imageName stringByAppendingString:@"-Landscape"];
break;

imageName = [imageName stringByAppendingString:@"-Landscape"];
break;
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
default:
imageName = [imageName stringByAppendingString:@"-Portrait"];
break;
imageName = [imageName stringByAppendingString:@"-Portrait"];
break;
}
}
}
// if(imageName)
// {
// imageName = [imageName stringByAppendingString:@".png"];
// }
// if(imageName)
// {
// imageName = [imageName stringByAppendingString:@".png"];
// }
return imageName;
}

Expand All @@ -280,7 +283,7 @@ - (UIImage*) getImageFromName:(NSString*) imageName
NSString* imagePath = [imageName stringByAppendingString:@".png"];
image = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingString:imagePath]];
if(image)
return image;
return image;

//try to take out hyfens and see if that works (Compatbility with Outsystems mobile issue)
imageName = [imageName stringByReplacingOccurrencesOfString:@"-" withString:@""];
Expand Down

0 comments on commit 20c451b

Please sign in to comment.