1

I wanted to implement the in-app version for my app, but I don't understand why is not working? The output showing i was added successfully, but when i open the pList file from my Xcode, its not changing? Why is it? Here is my code:

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")
            }


        }


}

plist

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
minimomo
  • 581
  • 1
  • 6
  • 16
  • You cannot write into info.plist (nor into any other file in the application bundle) at runtime. – vadian Jul 12 '16 at 08:58
  • @vadian but i wanted to implement my own api version to force user update everytime, how do i do it? pls guide me – minimomo Jul 12 '16 at 09:07

2 Answers2

2

You can't update your (Bundle plist) at run-time. If you want use then you just make one copy on your Document Directory then you can perform any operation.

Write and Read a plist in swift with simple data

Community
  • 1
  • 1
Mitul Marsoniya
  • 5,272
  • 4
  • 33
  • 57
1

Apple not allow to update info.plist update at runtime in app.