Urban Airship and AirshipConfig.plist
Asked Answered
F

2

7

is there a possibility to have XCode configure the AirshipConfig.plist for iOS depending on the build target? Urban Airship at the moment only supports 2 configurations, set in the AirshipConfig.plist, but I want to have 3 or more. Does anyone have experience if it's possibile to switch the config file depending on the target? Does UA require the file to have exactly the above name?

It's really a drawback that UA does not offer any options for more than 2 configs. UA support says it's not possible at the moment, but I thought maybe switching the file dynamically would be an option.

Regards Kim

Feliciafeliciano answered 15/1, 2013 at 10:1 Comment(0)
F
6

I found out myself. If anyones interested: Just create subfolders for each configuration and put the corresponding AirshipConfig.plist in there. Then create different targets for the configurations and set the target membership of the right file to that target. That's all.

Feliciafeliciano answered 17/1, 2013 at 9:39 Comment(1)
Fantastic idea. Worked great for me!Braiding
I
1

Here is the code I use to generate the airshipConfigOptions for three of my targets. The targets have macros in the build settings for each target: {TARGET_A, TARGET_B, TARGET_C}:

- (void)urbanAirshipTakeoffWithLaunchOptions:(NSDictionary *)launchOptions {

    // Init Airship launch options
    NSMutableDictionary *takeOffOptions = [[NSMutableDictionary alloc] init];
    [takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];

    // Build the Urban Airship TakeOffOptions

    // Create Airship singleton that's used to talk to Urban Airship servers.
    // Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
    NSMutableDictionary *airshipConfigOptions = [[NSMutableDictionary alloc] init];

    /*
     * Set up the Push keys based on target
     */
    _uaApp = @"unknown";

    // iFlightBag TARGET_A
#ifdef TARGET_A
    NSLog(@"Appdelegate_Pad:didFinishLaunchingWithOptions - TARGET_A");
    [airshipConfigOptions setValue:@"xxx" forKey:@"DEVELOPMENT_APP_KEY"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"DEVELOPMENT_APP_SECRET"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"PRODUCTION_APP_KEY"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"PRODUCTION_APP_SECRET"];
    _uaApp = "@TARGET_A";
#endif

    // iFlightBag TARGET_B
#ifdef TARGET_B
    NSLog(@"Appdelegate_Pad:didFinishLaunchingWithOptions - TARGET_B");
    [airshipConfigOptions setValue:@"xxx" forKey:@"DEVELOPMENT_APP_KEY"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"DEVELOPMENT_APP_SECRET"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"PRODUCTION_APP_KEY"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"PRODUCTION_APP_SECRET"];
    _uaApp = @"TARGET_B";
#endif

    // iFlightBag 
#ifdef TARGET_C
    NSLog(@"Appdelegate_Pad:didFinishLaunchingWithOptions - TARGET_C");
    [airshipConfigOptions setValue:@"xxx" forKey:@"DEVELOPMENT_APP_KEY"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"DEVELOPMENT_APP_SECRET"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"PRODUCTION_APP_KEY"];
    [airshipConfigOptions setValue:@"xxx" forKey:@"PRODUCTION_APP_SECRET"];
    _uaApp = @"TARGET_C";
#endif

    // If CONFIGURATION_Debug is defined, then use the development servers, else use the production servers
#ifdef CONFIGURATION_Debug
    [airshipConfigOptions setValue:@"NO" forKey:@"APP_STORE_OR_AD_HOC_BUILD"];
    NSLog(@"Using Development Servers at Urban Airship");
    _uaApp = [_uaApp stringByAppendingString:@"_dev"];
#else
    [airshipConfigOptions setValue:@"YES" forKey:@"APP_STORE_OR_AD_HOC_BUILD"];
    NSLog(@"Using Production Servers at Urban Airship");
#endif


    // Erase stored user informaton - set in settings?
    if(self.getEraseUser) [airshipConfigOptions setValue:@"YES" forKey:@"DELETE_KEYCHAIN_CREDENTIALS"];

    // Set and start Urban Airship
    [takeOffOptions setValue:airshipConfigOptions forKey:UAirshipTakeOffOptionsAirshipConfigKey];
    [UAirship takeOff:takeOffOptions];

    // -----
    // Set up Urban Airship Inbox
    // Set up the list and message view controllers for the master and detail panels, respectively.

    // If the application gets an UAInbox message id on launch open it up immediately. Only works for the default inbox

    //Init the UI
    [UAInbox useCustomUI:[UAInboxUI class]];//sample UI implementation
    [UAInbox shared].pushHandler.delegate = [UAInboxUI shared];

    // If the application gets an UAInbox message id on launch open it up immediately.
    // Only works for the default inbox
    [UAInboxUI shared].inboxParentController = self.tabcontroller;
    [UAInboxPushHandler handleLaunchOptions:launchOptions];

    if ([[UAInbox shared].pushHandler hasLaunchMessage]) {
        [[[UAInbox shared] uiClass] loadLaunchMessage];
    }

    // Register for notifications
    [[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                         UIRemoteNotificationTypeSound |
                                                         UIRemoteNotificationTypeAlert)];
}
Inodorous answered 18/1, 2013 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.