Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-06-2012, 09:49 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 39
troop231 is on a distinguished road
Question Help needed in solving this mess.

Hello, I need some input on possible ways I can solve a huge issue in one of my current apps.

Basically, my app on the app store ships with about ~700MB of PDFs stored in the mainbundle. I've had a few people get annoyed with having to redownload the app update only when I update a state or two's regulations. I agree with them, it is annoying, and I therefore want to put a significant update into my app that will allow me to basically never have to submit an app update again.

Here's what I want to do: 1.) Move all mainbundle "shipped" PDFs into a Documents folder which will tie in with point #2.) Connect to a website's folder and view the PDFs I put in there as updates. 3.) Before displaying the updates, check the modified date of the PDF files on the server against the "shipped" PDFs, then display only the ones that need updated each in a table cell and alloc an Update All button; if no new PDFs are found, display a UIAlert "No updates found" 4.) If there are updates, and the user clicks the Update All button, then begin download (with a progress indicator) and overwrite the "shipped" PDFs with the newer ones.

Sorry for the long post, I'm sure all of this is doable, I just need some help/input on where to get started.

Thank you in advance
troop231 is offline   Reply With Quote
Old 02-07-2012, 02:46 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Helsinki
Posts: 304
fiftysixty is on a distinguished road
Default

Quote:
Originally Posted by troop231 View Post
Hello, I need some input on possible ways I can solve a huge issue in one of my current apps.

Basically, my app on the app store ships with about ~700MB of PDFs stored in the mainbundle. I've had a few people get annoyed with having to redownload the app update only when I update a state or two's regulations. I agree with them, it is annoying, and I therefore want to put a significant update into my app that will allow me to basically never have to submit an app update again.

Here's what I want to do: 1.) Move all mainbundle "shipped" PDFs into a Documents folder which will tie in with point #2.) Connect to a website's folder and view the PDFs I put in there as updates. 3.) Before displaying the updates, check the modified date of the PDF files on the server against the "shipped" PDFs, then display only the ones that need updated each in a table cell and alloc an Update All button; if no new PDFs are found, display a UIAlert "No updates found" 4.) If there are updates, and the user clicks the Update All button, then begin download (with a progress indicator) and overwrite the "shipped" PDFs with the newer ones.

Sorry for the long post, I'm sure all of this is doable, I just need some help/input on where to get started.

Thank you in advance
On the server side, you'll need a bit of code that checks the modified dates of the relevant files. I did something like that a couple of years back using PHP, and it was pretty straightforward. I parse the modified dates into plist format so it is really easy to retrieve the data from the iOS device. After that it should be pretty easy to go forward, just download the modified files to the device and
store them in the Documents folder.

Here is the PHP code I whipped up, though for my purposes it only checks if any of the files have been modified and returns the last modified date. But you should be able to modify the code to suit your purposes. Also, I had zero knowledge of PHP so I don't know how good my solution is, but it has worked well so far.

Code:
<?php 
header("Content-type: text/xml");

$file1_edited = filemtime('./file1.html');
$file2_edited = filemtime('./file2.html');
$file3_edited = filemtime('./file3.html');
$edited = $file1_edited;
if ($file2_edited > $edited) {
    $edited = $file2_edited;
}
if ($file3_edited > $edited) {
    $edited = $file_edited;
}

$xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 
$xml_output .= "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n";
$xml_output .= "<plist version=\"1.0\">\n";
$xml_output .= "<dict>\n";
$xml_output .= "<key>time</key>\n";
$xml_output .= "<string>".$edited."</string>\n";
$xml_output .= "<key>date</key>\n";
$xml_output .= "<string>".date("Y-m-d H:i:s O", $edited)."</string>\n";
$xml_output .= "</dict>\n";
$xml_output .= "</plist>\n";

echo $xml_output;

?>
Then, in my app code I just call
Code:
[NSDictionary dictionaryWithContensOfURL:[NSURL URLWithString:@"http://www.yourdomain.com/yourfile.php"]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-M-d HH:mm:ss Z"];
NSDate *lastModifiedDate = [dateFormatter dateFromString:[lastModifiedDict objectForKey:@"date"]];
That works for me since I have just one date I'm interested in. For you, the NSDictionary should contain the filename and last modified date for each file, but that shouldn't be too hard to implement.
fiftysixty is offline   Reply With Quote
Old 02-07-2012, 09:06 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 39
troop231 is on a distinguished road
Default

Quote:
Originally Posted by fiftysixty View Post
On the server side, you'll need a bit of code that checks the modified dates of the relevant files. I did something like that a couple of years back using PHP, and it was pretty straightforward. I parse the modified dates into plist format so it is really easy to retrieve the data from the iOS device. After that it should be pretty easy to go forward, just download the modified files to the device and
store them in the Documents folder.

Here is the PHP code I whipped up, though for my purposes it only checks if any of the files have been modified and returns the last modified date. But you should be able to modify the code to suit your purposes. Also, I had zero knowledge of PHP so I don't know how good my solution is, but it has worked well so far.

Code:
<?php 
header("Content-type: text/xml");

$file1_edited = filemtime('./file1.html');
$file2_edited = filemtime('./file2.html');
$file3_edited = filemtime('./file3.html');
$edited = $file1_edited;
if ($file2_edited > $edited) {
    $edited = $file2_edited;
}
if ($file3_edited > $edited) {
    $edited = $file_edited;
}

$xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 
$xml_output .= "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n";
$xml_output .= "<plist version=\"1.0\">\n";
$xml_output .= "<dict>\n";
$xml_output .= "<key>time</key>\n";
$xml_output .= "<string>".$edited."</string>\n";
$xml_output .= "<key>date</key>\n";
$xml_output .= "<string>".date("Y-m-d H:i:s O", $edited)."</string>\n";
$xml_output .= "</dict>\n";
$xml_output .= "</plist>\n";

echo $xml_output;

?>
Then, in my app code I just call
Code:
[NSDictionary dictionaryWithContensOfURL:[NSURL URLWithString:@"http://www.yourdomain.com/yourfile.php"]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-M-d HH:mm:ss Z"];
NSDate *lastModifiedDate = [dateFormatter dateFromString:[lastModifiedDict objectForKey:@"date"]];
That works for me since I have just one date I'm interested in. For you, the NSDictionary should contain the filename and last modified date for each file, but that shouldn't be too hard to implement.
Thank you for posting. I have a couple of questions, in the php code it looks like you have to type out each file name, is there a way it can determine itself to see how many files are in the folder so I don't have to modify the php everytime I add a new PDF to the server?

Also, how can I go about migrating my current mainbundle PDFs into a documents directory?

Thanks in advance!
troop231 is offline   Reply With Quote
Old 02-07-2012, 03:46 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Helsinki
Posts: 304
fiftysixty is on a distinguished road
Default

Quote:
Originally Posted by troop231 View Post
Thank you for posting. I have a couple of questions, in the php code it looks like you have to type out each file name, is there a way it can determine itself to see how many files are in the folder so I don't have to modify the php everytime I add a new PDF to the server?

Also, how can I go about migrating my current mainbundle PDFs into a documents directory?

Thanks in advance!
Yeah, in my case I have just three files that I need to check, but you could do it in a dynamic way, though I don't know how. I'm not really versed at PHP, I created my code with a bit of Googling so I suppose it wouldn't be too hard to modify it to list the contents of a directory and work with that instead of hardcoded filenames.

As for the migration, since the main bundle is off limits, you have to remove the PDFs from the bundle in an update to the app, and then download the PDFs to the documents directory. That is, I believe, the simplest and easiest approach.
fiftysixty is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 409
17 members and 392 guests
Alex-alex, Apptronics RBC, baja_yu, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, n00b, pbart, reficul, Retouchable, Sami Gh, usernametaken, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:17 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0