I have a simple HTML page that prints on screen the date of last update of a file as follows (I have little knowledge of PHP):
<HTML>
<HEAD> </HEAD>
<BODY>
<?php
$filename = 'nameFile.xml';
if (file_exists($filename)) {
echo "$filename Was Last modified:". date ("F d Y H: i: s.", filemtime($filename));
}
?>
</BODY>
</HTML>
I would like to make a request through NSURLConnection in Objective C, and would like me to return the date in a variable, how can I do this? Do I have to parse the HTML page, or can I get the value directly of the last modification?
Thanks for your help.
What about using the Last-Modified
header value?
You should use create a simple webservice on the php side to transfer this data in a structured format. You should use an existing objective-c library to parse the results. The format you choose is up to you. SOAP, XML-RPC, REST, and JSON are used often. Val's idea of setting the HTTP header is REST-ish, a simple and a good solution. The worst way would be to parse out plain text.
This would be the PHP code to set the Last-Modified header:
header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', strtotime($date_string_here)));
Assuming retData
is the string representing the returned value from your website:
NSString * tempString = [[NSString alloc] initWithData:retData encoding:NSUTF8StringEncoding];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:tempString];
NSLog("check returned string: %@ date= %@", tempString, date);