我想为我的应用实现应用内版本,但我不明白为什么不工作?显示i的输出已成功添加,但是当我从我的Xcode打开pList文件时,它没有改变?为什么?这是我的代码:
func version(){
let urlString = jocomAPIKey + "/feed/version"
let CFBundleShortVersionKey = "CFBundleVersion"
//First get the nsObject by defining as an optional anyObject
let nsObject: AnyObject? = NSBundle.mainBundle().infoDictionary!["CFBundleVersion"]
let version = nsObject as! String
print("app version: \(version)")
Alamofire.request(.POST, urlString , parameters: ["os" : "iphone"])
.responseData { response in
let versionXML = SWXMLHash.parse(response.data!)
let versionString = (versionXML["rss"]["channel"]["item"]["version"].element?.text)
print("version string: \(versionString)")
if let plist = Plist(name: "Info") {
let dict = plist.getMutablePlistFile()!
dict[CFBundleShortVersionKey] = versionString
//3
do {
try plist.addValuesToPlistFile(dict)
print("added")
} catch {
print(error)
}
//4
print(plist.getValuesInPlistFile())
} else {
print("Unable to get Plist")
}
}
}
答案 0 :(得分:2)
您无法在运行时更新(Bundle plist)。如果您想使用,那么您只需在Bla Bla Bla
上创建一个copy
,然后就可以执行任何Document Directory
。
答案 1 :(得分:0)
Apple不允许在应用程序运行时更新info.plist更新。