Urban Airship 和 AirshipConfig.plist

Posted

技术标签:

【中文标题】Urban Airship 和 AirshipConfig.plist【英文标题】:Urban Airship and AirshipConfig.plist 【发布时间】:2012-12-29 09:37:42 【问题描述】:

是否有可能让 XCode 根据构建目标为 ios 配置 AirshipConfig.plist? Urban Airship 目前只支持 2 种配置,在 AirshipConfig.plist 中设置,但我想要 3 种或更多。如果可以根据目标切换配置文件,有没有人有经验? UA 是否要求文件具有上述名称?

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

问候 金

【问题讨论】:

【参考方案1】:

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

【讨论】:

好主意。对我来说效果很好!【参考方案2】:

这是我用来为我的三个目标生成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)];

【讨论】:

以上是关于Urban Airship 和 AirshipConfig.plist的主要内容,如果未能解决你的问题,请参考以下文章

Urban Airship 收不到富推

无法从 Urban Airship 获得推送通知

使用 Urban AirShip 和 Rails 3 for iphone 推送通知

Urban Airship:默认状态栏通知的自定义图标

Urban Airship 在呼叫起飞时坠毁

如何使用 Urban AirShip (Swift) 获取 appDelegate