以编程方式编辑plist

我从来没有记住要改变任何东西,所以我只是使用苹果提供的这个方法( https://developer.apple.com/library/mac/qa/qa1361/_index.html ) mdebugging或生产,所以我的所有更改都是为我做的(切换到真正的广告,使用生产url等)

我有以下plist城市飞艇

AirshipConfig.plist

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>analyticsEnabled</key> <false/> <key>inProduction</key> <false/> <key>developmentAppKey</key> <string>SOMESTRINGHERE</string> <key>developmentAppSecret</key> <string>SOMESTRINGHERE</string> <key>productionAppKey</key> <string>SOMESTRINGHERE</string> <key>productionAppSecret</key> <string>SOMESTRINGHERE</string> </dict> </plist> 

现在对于Urban Airship inProduction ,当我发布到应用程序商店时,必须将inProduction更改为true ,当我正在debugging时,将false更改为false

所以在我的应用程序委托,我试图改变plist与以下if。 我仍然试图让plist的内容看到它正在工作,但我一直得到(null)作为我的NSLog

 if([Def AmIBeingDebugged]){ //Development set to false NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"AirshipConfig" ofType:@"plist"]; NSLog(@"%@", [NSArray arrayWithContentsOfFile:plistPath]); }else{ //Production set to true } 

任何帮助设置正确的plist价值将不胜感激,因为我已经打了一堵墙,不知道为什么它总是(空),因为我想我会需要的内容,所以我可以重写文件。

首先为所有Xcode构buildconfiguration创buildAirshipConfig.plist单独副本,并以AirshipConfig_$(CONFIGURATION).plist (例如AirshipConfig_Debug.plistAirshipConfig_Release.plist )的格式AirshipConfig_$(CONFIGURATION).plist 。 然后更新他们的内容到任何你想要的(例如,将inProduction设置为适当的值。)

然后在Xcode中为您的应用程序目标创build一个新的“运行脚本”构build阶段,并为其命名为“复制Urban Airshipconfiguration文件捆绑”。 添加这个脚本的内容:

 cp "${SRCROOT}/MyProjectName/AirshipConfig_${CONFIGURATION}.plist" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AirshipConfig.plist" 

这会将正确的构buildconfiguration的configuration文件复制到您的应用程序包中,并使用外部库期望的文件名( AirshipConfig.plist )。 在上面的例子中,确保configuration文件的源path是正确的。