Sometimes you have various applications that use their own MOCAConfig.plist. In this case the best approach is to initialize the SDK without the .plist, but using only the code. Let's say we need 3 versions of the App (i.e. Pikachu, Rattata and Dodrio):
1 . Click on your project name in the left navigation bar, and select the target, let's say Pikachu.
2 . Go to Build Settings and look for Preprocessor Macros. If you are using Cocoapods, you will see that there is already a flag like this
COCOAPODS=1. So add a new preprocessor Macro as follows
Important: if you are using Swift, include them in other swift flags with the following format:
3 . Repeat the process for each one of the targets using its respective names.
4 . Now, in a
Utils class or similar , define the keys as follows:
#import "Utils.h" #import "MOCAConfig.h" #import ...... ifdef PIKACHU #define APP_KEY @"pikachuKey" #define APP_SECRET @"pikachuSecret" #elif RATATTA #define APP_KEY @"rattataKey" #define APP_SECRET @"rattataSecret" #elif DODRIO #define APP_KEY @"dodrioKey" #define APP_SECRET @"dodrioSecret" #endif //your code
#if PIKACHU let appKey = "pikachuKey" let appSecret = "pikachuSecret" #elseif RATTATA let appKey = "rattataKey" let appSecret = "rattataSecret" #elseif DODRIO let appKey = "dodrioKey" let appSecret = "dodrioSecret" #endif
When you initialize the MOCA SDK, first create a MOCAConfig file using:
MOCAConfig *config = [MOCAConfig defaultConfigForAppKey:APP_KEY andSecret:APP_SECRET];
Or the equivalent Swift version.
So the initialization code will look something like:
BOOL mocaReady = [MOCA initializeSDK:[Utils mocaConfig]];
Or the equivalent in Swift. In this example we are loading the config file in an Utils class that uses the keys depending on the defined flags.
MOCAConfig object will contain all the default settings in a similar manner you have in the MOCAConfig.plist, so you can start or stop any service you need for your application.