-
-
Save hspinks/c313d00cb10e5c8baf14 to your computer and use it in GitHub Desktop.
iOS Environment-Specific Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Environment.h | |
// | |
// Created by Hunter Spinks on 7/8/14. | |
// | |
#import <Foundation/Foundation.h> | |
@interface Environment : NSObject { | |
NSString *apiBaseUrl; | |
NSString *apiKey; | |
NSString *facebookAppId; | |
NSString *facebookDisplayName; | |
} | |
@property (nonatomic, retain) NSString *apiBaseUrl; | |
@property (nonatomic, retain) NSString *apiKey; | |
@property (nonatomic, retain) NSString *facebookAppId; | |
@property (nonatomic, retain) NSString *facebookDisplayName; | |
+ (Environment *)sharedInstance; | |
- (BOOL)isProduction; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Environment.m | |
// | |
// Created by Hunter Spinks on 7/8/14. | |
// | |
#import "Environment.h" | |
@interface Environment() | |
@property (nonatomic, strong) NSString *configuration; | |
@end | |
@implementation Environment | |
static Environment *sharedInstance = nil; | |
@synthesize apiBaseUrl; | |
@synthesize apiKey; | |
@synthesize facebookAppId; | |
@synthesize facebookDisplayName; | |
- (void)initializeSharedInstance | |
{ | |
NSBundle *bundle = [NSBundle mainBundle]; | |
self.configuration = [[bundle infoDictionary] objectForKey:@"Configuration"]; | |
NSString *environmentsPlistPath = [bundle pathForResource:@"Environments" ofType:@"plist"]; | |
NSDictionary *environments = [[NSDictionary alloc] initWithContentsOfFile:environmentsPlistPath]; | |
NSDictionary *environment = [environments objectForKey:self.configuration]; | |
self.apiBaseUrl = [environment valueForKey:@"apiBaseUrl"]; | |
self.apiKey = [environment valueForKey:@"apiKey"]; | |
self.facebookAppId = [environment valueForKey:@"facebookAppId"]; | |
self.facebookDisplayName = [environment valueForKeyPath:@"facebookDisplayName"]; | |
} | |
+ (Environment *)sharedInstance | |
{ | |
@synchronized(self) { | |
if (sharedInstance == nil) { | |
sharedInstance = [[self alloc] init]; | |
[sharedInstance initializeSharedInstance]; | |
} | |
return sharedInstance; | |
} | |
} | |
- (BOOL)isProduction | |
{ | |
return [self.configuration isEqualToString:@"Release"] || [self.configuration isEqualToString:@"Debug"]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Development</key> | |
<dict> | |
<key>apiBaseUrl</key> | |
<string>DEVELOPMENT_API_URL</string> | |
<key>facebookAppId</key> | |
<string>DEVELOPMENT_APP_ID</string> | |
<key>facebookDisplayName</key> | |
<string>DEVELOPMENT_DISPLAY_NAME</string> | |
<key>apiKey</key> | |
<string>DEVELOPMENT_API_KEY</string> | |
</dict> | |
<key>Staging</key> | |
<dict> | |
<key>apiBaseUrl</key> | |
<string>STAGING_API_URL</string> | |
<key>facebookAppId</key> | |
<string>STAGING_APP_ID</string> | |
<key>facebookDisplayName</key> | |
<string>STAGING_DISPLAY_NAME</string> | |
<key>apiKey</key> | |
<string>STAGING_API_KEY</string> | |
</dict> | |
<key>Release</key> | |
<dict> | |
<key>apiBaseUrl</key> | |
<string>RELEASE_API_URL</string> | |
<key>facebookAppId</key> | |
<string>RELEASE_APP_ID</string> | |
<key>facebookDisplayName</key> | |
<string>RELEASE_DISPLAY_NAME</string> | |
<key>apiKey</key> | |
<string>RELEASE_API_KEY</string> | |
</dict> | |
<key>Debug</key> | |
<dict> | |
<key>apiBaseUrl</key> | |
<string>DEBUG_API_URL</string> | |
<key>facebookAppId</key> | |
<string>DEBUG_APP_ID</string> | |
<key>facebookDisplayName</key> | |
<string>DEBUG_DISPLAY_NAME</string> | |
<key>apiKey</key> | |
<string>DEBUG_API_KEY</string> | |
</dict> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lifesaver. I owe you a beer