是否有可能让 XCode 根据构建目标为 iOS 配置 AirshipConfig.plist?Urban Airship 目前只支持 2 种配置,在 AirshipConfig.plist 中设置,但我想要 3 种或更多。如果可以根据目标切换配置文件,有没有人有经验?UA 是否要求文件具有上述名称?
UA 不提供超过 2 个配置的任何选项确实是一个缺点。UA 支持表示目前不可能,但我认为动态切换文件可能是一种选择。
问候金
是否有可能让 XCode 根据构建目标为 iOS 配置 AirshipConfig.plist?Urban Airship 目前只支持 2 种配置,在 AirshipConfig.plist 中设置,但我想要 3 种或更多。如果可以根据目标切换配置文件,有没有人有经验?UA 是否要求文件具有上述名称?
UA 不提供超过 2 个配置的任何选项确实是一个缺点。UA 支持表示目前不可能,但我认为动态切换文件可能是一种选择。
问候金
我自己发现了。如果有人感兴趣:只需为每个配置创建子文件夹并将相应的 AirshipConfig.plist 放在那里。然后为配置创建不同的目标,并将正确文件的目标成员资格设置为该目标。就这样。
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)];
}