Updating an iphone app with plist - xcode

I am a question about plist. If i have already released an app say version 1.0, which contain a plist, allows user to save their data in. If i now release a version 2.0, will the plist data entered by the user in the previous version being deleted.
I have tried on my phone, by using build and run from the xcode seems it doesn;t delete the pervious. But i am not sure will it be the same in itunes store.
Thank you.

Since you're saying that user's save their data in the plist, I will assume you are saving that plist to the documents directory. If that is the case, I don't see why it will be an issue as the directory is persistent between app updates. And if you are providing a new plist file with this update then it won't overwrite that plist file unless you instruct it to as the new plist file will be inside the bundle. You might want to check whether a plist exists already in the documents directory. If it exists, perform some kind of merge operation between both the plist files.

Related

Xcode - set folder reference path via script or plist

I've got a folder reference in Xcode that needs to be configurable by the user. I'd prefer to use a script or plist to set its Location and Full Path properties at build time. I've looked around the web but can't seem to find a way of doing this - is there?

OS X: NSUserDefaults not saved

I have a sandboxed app for OSX and I saved some data in NSUserDefaults, everything was fine until I deleted the plist file from the ~Library/Preferences/ directory.
I thought the app should recreat it but it did not. When I debug I see that
[[NSUserDefaults standardUserDefaults] synchronize] method returns YES
and data are saved in the class but when I restart the app user defaults is empty.
Even if I copy those plist file from backup to the Preferences directory, the app does not see it.
Of course the plist should be saved in the Containers/my app bundle id/Data/Library/Preferences and when I copy the plist file from backup to that directory, the app can see it, but why that file is not recreated when I deleted it?
Does anybody know why is that?
Check this question - might be related to caching or prefs location when running in the sandbox:
Mac sandbox created but no NSUserDefaults plist
I had this problem, which is caused by deleting the files manually. What you can do instead is to use the defaults terminal command. This way I was able to reset the defaults without breaking things. Replace "bundle-identifier" with your bundle id.
To view the current values:
defaults read bundle-identifier
To remove stored values:
defaults delete bundle-identifier

NSMetadataQuery does not find documents after moving them to iCloud

In my Mac app I have an NSMetadataQuery to watch the app's iCloud directory. When the user decides to enable iCloud from within the app I do the following in this order:
Call [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil] to establish access to the iCloud container
Start a NSMetadataQuery to find all files (pattern: "*") in the iCloud container
Now I iterate over all files in the local container and move them to iCloud by using [fileManager setUbiquitous:YES itemAtURL:fileURL destinationURL:targetURL error:&error]
I have two types of documents that I move to iCloud:
The actual documents stored as file packages
For each document I have a .preview file as simple binary file
My problem is that the meta data query only returns my binary preview files, but not my actual documents until I relaunch my app (or open a Finder window of the app's iCloud folder from the Terminal - in this case my app gets another query result with all files).
So is this some weird caching issue? Is this because the documents are file packages and not simple binary files?
I don't see why that should be a problem. If I restart my app the query does return all files correctly.
Could this be a problem with the way my custom document type is exported in Info.plist?
Could this be a problem with the way my custom document type is
exported in Info.plist?
I suppose so: the issue you are describing is most likely because your document format is a file package (I assume written with NSFileWrapper). Remember that the package bit is set when writing the file, so if you have other apps writing to iCloud, that could make the issue much more confusing as it's not about interpreting a file bundle but writing it in a correct manner.
NSMetadataQuery unfortunately ignores folders, so your files will never be reported back unless you have correctly registered your filetype as bundle in the application that writes the file to the iCloud container.
There are a lot of similar and potentially confusing settings in the info.plist, so many things that can go wrong. I experienced an issue when I registered my document filetype correctly on OS X, but failed to do so on iOS: https://stackoverflow.com/a/14993694/388412
The first thing you should do is to go to https://developer.icloud.com/#documents and see if you're looking at files (correct) or folders (problem).
Work on your info.plist document types until you see the documents as files, then it should work.

NSSavePanel for saving a file after sandboxing

I have a mac AVRecording app, which records a video and save it to a location selected via NSSavePanel. It was working fine till I sandboxed the app.
For sandboxing I have added the following entitlements
com.apple.security.files.user-selected.read-write
com.apple.security.assets.movies.read-write
com.apple.security.files.downloads.read-write
This enables saving to Downloads and movies folder only.
How is it possible to save my file to any desired location, Desktop, Documents etc ?
It's not clear from your question whether you are referring to saving a particular file (in which case you can use the NSSavePanel and manually copy the file using NSFileManager to write the file into the user-specified new file), or whether you are referring to having the user choose a location for all future downloads.
If you want to prompt the user for a location to use for future downloads, you'll need to use the secure bookmark entitlement and secure bookmarks to retain access to the folder.
There's another stackoverflow answer about sandboxing which covers the process of saving and using the secure bookmark.

MacOS X: Remove plist file when the app is removed

I am showing a license form at app startup, but it should be shown only at the first time the app launched. Not always. So, i tried to store a flag in plist or user defaults, but upon the app removing(move to trash), plist or userdefaults is not getting removed from system, thus i'm not able to achieve my task.
This is what i have been trying below,
I am storing a flag in plist file and save the file(in Documents directory) during App launch, so next time , i can read from there and find out whether the app is running first time or not. I am failing here, because even the app is removed(move to trash) from system, i am not able to remove this plist file.
I tried to set a flag in NSUserDefaults too, but after deleting the app and build again and launch the app, it still persists the previous value i stored. I am wondering, NSUserDefaults doesn't get deleted when app is deleted from system?
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setObject:#"1" forKey:#"APPLAUNCHED"]; // store user default
[ud synchronize];
Could someone please advise?
Thank you.
Neither user defaults nor the application sandbox get automatically removed when the application is deleted. I think there's no way to do that.

Resources