how to pen Iphone .plist file in Windows Machine? - iphone

In my Iphone application i have .plist file in which i am putting all the Input data. I will further use this data in the code: directly from .plist file.
The problem is that when i am going to open the .plist file in a windows machine, it is not showing its original content. It is just showing the Binary characters or junk characters.
Can any body help me out for how to open the .plist file in the Windows machine, so i can do my data entry in the .plist file in a windows machine also.
Any solution would be appreciated.

More likely than not, the plist is stored in a binary format for speed and size purposes (XML is bloated and slow to parse).
You'll need to explicitly save your data in a readable format manually or use NSPropertyListSerialization to serialize the property list into XML.
http://developer.apple.com/iphone/library/documentation/cocoa/Reference/Foundation/Classes/NSPropertyListSerialization_Class/Reference/Reference.html#//apple_ref/occ/clm/NSPropertyListSerialization/dataFromPropertyList:format:errorDescription:

Probably it's to late.
You can use xml editor,but not all of them can work with *.plist files. I use http://www.donkeydevelopment.com
PS
Apple use this document type definition:
< DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

Related

Importing text files into an iOS App

I noticed that when saving a file from within an iOS App using:
writeToFile:myFile atomically:YES
the resulting file is actually saved in XML format, and always has the following code:
<?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">
<array>
<string>Sentence 1</string>
<string>Sentence 2</string>
<string>Sentence 3</string>
<string>Sentence 4</string>
</array>
</plist>
So its always in an XML/Plist format.
But if I try to import into the App a text file which was NOT created from within an iOS App - it doesn't seem to know how to recognize it.
For example, if I take a plain text file created in TextEdit and drag it into my App's Documents folder and then run the App again, the App sees this new file, but when I try to load its contents using:
initWithContentsOfFile:myFile
the result I get is: (null)
Is this because the default format of files created in TextEdit is ".rtf"? Or should I be using an altogether different method to read plain-text files into the App other than
initWithContentsOfFile:myFile?
Ultimately I'd like for the App to be able to load existing text files - maybe even Microsoft WORD files - and work with them. I'd like for the user to drag their existing files into the App's folder in iTunes, and then sync their device with iTunes - which will then copy these new files onto the device and when they run their App again, the app will see the new files and be able to open them and read their contents.
Any suggestions?
You've mentioned the writeToFile:atomically: method but you haven't told us what class this method is being called on. For example, NSString, NSArray, NSDictionary and other classes have a method with this name and they all behave differently as might expect given teh different types of data structures.
From the above file output, it looks like you're probably calling this on an NSArray which is why it gets written in Plist format. I assure you that strings get written plainly if you using an NSString, eg:
NSString *s = #"A string";
[s writeToFile:path atomically:YES];
will produce a file with:
A String
You may want to convert various other data structures into a string before you write it to a file.

Is it possible to modify/update the plist file programmatically without replacing it?

In my application
I want to change only some content of the file.
For doing that I am fetching the plist file in dictionary.
Modifying the dictionary and then Re-Writing the whole plist file.
Is it possible to modify the plist file directly or some content of the plist file.
It's not possible to modify a plist file without rewriting the whole file. If your plist file is so big that it takes too long to rewrite the whole thing, you should look at using a SQLite database instead, and perhaps adopting Core Data.
If you are talking about Info.plist or any resource inside your bundle (i.e.: inside MyApp.app folder) the answer is NO.
Files inside your bundle are read-only. So you cannot override them.
If you are talking about other files that could be in Documents or Cached folder then the answer is YES.

XCode reports localized plist is corrupt

I have a plist file that I used in my app that I can localize so I get two entries in my project, one for English and one for Spanish and when I compile an run the app it works but of course at this stage the contents are identical.
I then in Finder replace the Spanish plist with one that has been translated for me into Spanish and I can in the XCode editor view the content without problem.
However when I try to compile I get an error stating:
.../en.lproj/myData.plist:0: error: reading plist: The data couldn’t be read because it has been corrupted.
But the English one has not been touched?
Surely you can copy a localized file into the project in this manner?
open disk utility repair permissions.
open terminal and run this command:
plutil -s /somewhere/yourfile1.plist
It will make you focus with all details of the problem by showing you the exact error and line. So you'll have to go the reported line & fix it by yourself with a text editor.
One thing that can happen is someone messed up one of your tags.
In Xcode right click on your Spanish plist, select Open AS then Source Code
Then check your plist to ensure all of your opening and closing tags are still there, there are no typos, are there any garbage characters in there, and that you are not trying to use a string in an integer etc:
Example:
<?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>1</key>
<dict>
<key>a</key>
<string>a1</string>
<key>b</key>
<string>b1</string>
</dict>
<key>2</key>
<dict>
<key>a</key>
<string>a2</string>
<key>b</key>
<string>b2</string>
</dict>
<key>3</key>
<dict>
<key>a</key>
<string>a3</string>
<key>b</key>
<string>b3</string>
</dict>
</dict>
</plist>
I once had some problems when something was copied and pasted into Xcode from a PDF (some kind of incorrect symbol maybe?) and it worked fine when I just re-entered it. Also its often difficult to generate a valid plist from a word processor.
That can also happen with strings file if you forget the semicolons at the end of the lines. Silly me.
This can also happen if you have an & within a string.
Replace:
<string>SomeText & SomeMoreText</string>
With:
<string>SomeText & SomeMoreText </string>
For benefit of anyone who had my exact problem:
I had the corrupt plist problem too.
My plist had been generated by exporting a spreadsheet in OpenOffice to CSV (in UTF-8 format). Then I'd convert the CSV file to a plist using a simple Python script I'd written. I believe my problem was that there were some cell reference errors in the spreadsheet I saved (i.e. the cells said "Err:511"). The existence of errors was causing the UTF-8 export to fail somehow, hence the corrupt plist.
I have not absolutely verified the above was the case, but I'm pretty sure that was the problem: after I fixed the errors in some cells in OpenOffice, my plist works again.
This answer demonstrates the use of the iconv command to verify a file is correctly encoded -- could be useful in cases like this.
This happened to me because I managed to drop a random quotation mark (") in my plist. Removed it and got it to work.
I opened the file in TextWrangler all used Cmd-F to search for any characters that might be causing the offence.
For me it was a space in the name of localized string:
Instead of this_is_the_string_we_will_translate
I had this_is_the string_we_will_translate.
Tricky one to spot.
A great place to start debugging plists is to use an XML validator such as: http://www.w3schools.com/xml/xml_validator.asp
This feature is also built into most web development environments.
Happened to me, missed 0:
2012-12-9T06:00:00Z
should be
2012-12-09T06:00:00Z

How to access and use the "plist version" information in a Property List file

I'm currently using *.plist files for my iPhone app to store information that is later read into strings as NSArray or NSDictionary equivalents. I will be updating these files periodically and downloading them to the application if a new version is found. I would like to use the <plist version="1.0"> string located in each *.plist file to make these comparisons since it won't interfere with the actual content of the plist file.
My question: is it possible to access this information and use it in the manner I describe, or is this version information describing the version of the *.plist protocol and not the actual file itself? For example, can I change this to: <plist version="1.1"> for a new version of the file, read this version info and update the file if newer? If this is possible, I haven't found a way to extract this information using the iPhone SDK (the comparison and update part will be easy).
I'm pretty sure you should'nt touch that. It's probably used by apple for future-compability (or future backwards compability, if you prefer). So that if/when they change the syntax of plists, old ones will still work.
Easiest would be to have the first entry contain the version number, or possible as a part of the file name. Or maybe even at a completetley different place, like in a database or as a part of a file structure on the server.

How do you package clickable url's with your application?

I asked a similar question a while ago but didn't get a satisfactory answer, so I was wondering if there was a different approach a guy could take.
What is the format for making a web link that you can deploy with your application? One that might show up in the start menu as a link to said app vendor's website.
It should work in any modern OS and with any reasonably modern browser (i.e. >= IE6, although I'm not sure that's a relevant issue)
There is no cross-platform way to do this.
Freedesktop-compliant systems can use xdg-open
Mac users can use open
Debian derivatives can use sensible-browser (or install xdg-open, usually)
Windows users can use *.url files
Or, of course, you could implement xdg-open and package it with your app on systems that don't have it
Or implement your own util that's completely different and associate it with the right files
The format is different on different platforms.
On Windows, you can use a .url file. Here's a description of the format. You can also create one by just dragging a URL onto the desktop or into a folder. A simple example:
[InternetShortcut]
URL=http://stackoverflow.com/
On the Mac, you can also create a URL file by dragging a URL to the desktop. The format appears to be a file with a .webloc extension, containing a plist containing a dict, mapping the key URL to the URL in question:
<?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>URL</key>
<string>http://stackoverflow.com/</string>
</dict>
</plist>