Skip to content

Commit

Permalink
[TIMOB-15623] Read properties from encrypted tiapp.json
Browse files Browse the repository at this point in the history
  • Loading branch information
pec1985 committed Oct 31, 2013
1 parent a70ab48 commit 0056de4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions iphone/Classes/TiApp.h
Expand Up @@ -100,6 +100,11 @@ TI_INLINE void waitForMemoryPanicCleared() //WARNING: This must never be run o
*/
+(TiApp*)app;

/**
* Returns a read-only dictionary from tiapp.xml properties
*/
+(NSDictionary *)tiAppProperties;

/*
Convenience method to returns root view controller for TiApp instance.
@return The application's root view controller.
Expand Down
14 changes: 14 additions & 0 deletions iphone/Classes/TiApp.m
Expand Up @@ -809,5 +809,19 @@ + (NSDictionary *)dictionaryWithLocalNotification:(UILocalNotification *)notific
return [[event copy] autorelease];
}

+(NSDictionary *)tiAppProperties
{
static NSDictionary* props;
if(props == nil) {
NSString *tiAppPropertiesPath = [[TiHost resourcePath] stringByAppendingPathComponent:@"_ti_app.json"];
NSData *jsonData = [TiUtils loadAppResource: [NSURL fileURLWithPath:tiAppPropertiesPath]];
if (jsonData==nil) {
jsonData = [NSData dataWithContentsOfFile:tiAppPropertiesPath];
}
NSError *error = nil;
props = [[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error] retain];
}
return props;
}

@end
11 changes: 11 additions & 0 deletions iphone/Classes/TiAppPropertiesProxy.m
Expand Up @@ -8,6 +8,7 @@

#import "TiAppPropertiesProxy.h"
#import "TiUtils.h"
#import "TiApp.h"

@implementation TiAppPropertiesProxy {
NSData *_defaultsNull;
Expand Down Expand Up @@ -65,6 +66,10 @@ -(BOOL)propertyExists: (NSString *) key;
#define GETPROP \
ENSURE_TYPE(args,NSArray);\
NSString *key = [args objectAtIndex:0];\
NSString *appProp = [[TiApp tiAppProperties] objectForKey:key]; \
if(appProp) { \
return appProp; \
} \
id defaultValue = [args count] > 1 ? [args objectAtIndex:1] : [NSNull null];\
if (![self propertyExists:key]) return defaultValue; \

Expand Down Expand Up @@ -116,11 +121,17 @@ -(id)getObject:(id)args
else {
return theObject;
}

}

#define SETPROP \
ENSURE_TYPE(args,NSArray);\
NSString *key = [args objectAtIndex:0];\
NSString *appProp = [[TiApp tiAppProperties] objectForKey:key]; \
if(appProp) { \
DebugLog(@"Property \"%@\" already exist and cannot be overwritten", key); \
return; \
} \
id value = [args count] > 1 ? [args objectAtIndex:1] : nil;\
if (value==nil || value==[NSNull null]) {\
[defaultsObject removeObjectForKey:key];\
Expand Down

0 comments on commit 0056de4

Please sign in to comment.