I have some code that downloads a plist from a web server and stores it in the documents directory of the phone. My concern is that if the file becomes corrupt then it will effect the stability and user experience of the app.
I am coding defensively in the data read parts of the app, but wondered what advice is out there for checking the integrity of the file in the first place before the old one is over written. I am thinking of implementing some sort of computed value which is also stored in as a key in the plist for example.
Any thoughts about making this as robust as possible would be greatly appreciated.
Best regards
Dave
Have a look at
CommonCrypto/CommonDigest.h.The
CC_MD5(const void *data, CC_LONG len, unsigned char *md);function computes an MD5 hash.As part of the deployment of the files on the server, you can use OpenSSL to compute the hashs. The
openssl md5 filenamecommand computes an MD5 hash for a file. This can be integrated in a script.Then after your application has downloaded a file, it computes the hash of what’s been downloaded and compares it to the hash stored on the server.
Obviously, if you want to ensure the integrity of a plist file, this plist cannot contain its own hash.