Urban Airship and AirshipConfig.plist

时间:2013-01-15 10:01:20

标签: ios plist push urbanairship.com

是否有可能让XCode根据构建目标配置iOS的AirshipConfig.plist? Urban Airship目前仅支持2种配置,在AirshipConfig.plist中设置,但我希望有3个或更多。有没有人有经验,如果可能根据目标切换配置文件? UA是否要求文件具有完全相同的名称?

这是一个缺点,UA不提供超过2个配置的任何选项。 UA支持表示目前不可能,但我认为可能会动态切换文件。

此致 金

2 个答案:

答案 0 :(得分:5)

我发现了自己。 如果有兴趣: 只需为每个配置创建子文件夹,并在其中放置相应的AirshipConfig.plist。然后为配置创建不同的目标,并将正确文件的目标成员身份设置为该目标。 就是这样。

答案 1 :(得分:1)

以下是我用于为我的三个目标生成airshipConfigOptions的代码。目标在每个目标的构建设置中都有宏:{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)];
}