【发布时间】:2018-12-29 10:21:46
【问题描述】:
我从不记得在生产时更改任何内容,所以我只是使用苹果提供的这种方法 (https://developer.apple.com/library/mac/qa/qa1361/_index.html) 来检测我是在调试还是在生产中,所以我的所有更改都是为我完成的 (切换到真实广告,使用生产网址等)
我有以下用于 Urban Airship 的 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 更改为 true,在调试时将 false 更改为
因此,在我的应用委托中,我尝试使用以下 if 更改 plist。我仍在尝试获取 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 值的帮助将不胜感激,因为我碰壁了,无法弄清楚为什么它总是 (null),因为我认为我需要这些内容,以便我可以重写文件。
【问题讨论】:
-
plist 是字典,不是数组。
-
顺便说一句 - 你不能写回 plist 文件。 app bundle 是只读的。
-
您无法更改应用程序包中存在的文档。您正在存储并想要更改的值可能会更合适地存储在 NSUserDefaults 中。您可以使用 numberWithBool 将值嵌入到 NSNumber 中,轻松地在 NSUserDefaults 中搜索和更改 BOOL:
-
或者,使用
@YES或@NO。 -
好吧,我想使用 userdefaults,但 UrbanAirship 库从 plist 中读取,所以我认为我没有使用 userdefaults 的选项
标签: ios objective-c plist