I have my local data in json file like :
{
"locations": [
{
"title": "The Pump Room",
"place": "Bath",
"latitude": 51.38131,
"longitude": -2.35959,
"information": "The Pump Room Restaurant in Bath is one of the city’s most elegant places to enjoy stylish, Modern-British cuisine.",
"telephone": "+44 (0)1225 444477",
"visited" : true
},
{
"title": "The Eye",
"place": "London",
"latitude": 51.502866,
"longitude": -0.119483,
"information": "At 135m, the London Eye is the world’s largest cantilevered observation wheel. It was designed by Marks Barfield Architects and launched in 2000.",
"telephone": "+44 (0)8717 813000",
"visited" : false
},
{
"title": "Chalice Well",
"place": "Glastonbury",
"latitude": 51.143669,
"longitude": -2.706782,
"information": "Chalice Well is one of Britain's most ancient wells, nestling in the Vale of Avalon between the famous Glastonbury Tor and Chalice Hill.",
"telephone": "+44 (0)1458 831154",
"visited" : true
}
]
}
I want to update the json file which is there on the webserver whenever the refresh button touched?
The overall idea is to refresh the local data from server and use it without internet connectivity
Please Help...
The most appropriate solution depends on your exact requirements. For example:
and a few more.
If you can answer all requirements with No, then the most simple approach will suffice:
You can use
NSURLConnection
's convenient class method in the asynchronous version+ (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*))handler
You can find more info here: Using NSURL Connection
Furthermore Cocoa and Cocoa Touch provides more advances techniques in
NSURLConnection
andNSURLSession
to accomplish this task. You can read more in the official documentation URL Loading System Programming Guide.Here a short sample how you can use the asynchronous convenience class method:
sendAsynchronousRequest:queue:completionHandler:
:See also: [NSData] writeToURL:options:error
Edit:
handleError:
SHALL be implemented as follows:This ensures, when you display a UIAlertView for example, that your UIKit methods will be executed on the main thread.