I am lo开发者_Go百科oking to write a simple iPhone application to access some sort of data off the web. I was thinking something like the temperature in LA, the amount of snow in Vancouver etc. basically something that changes over time. Can anyone give me any pointers with regards to the current ways you can access variable remote data off the web for use within an application.
Should I be looking for online databases that I can query, some sort of feed, I am just not too sure how you go about this.
any examples or pointers would be much appreciated.
gary
You can try hit the URL and parse the webpage itself. I'd suggest reading up on NSURL* classes. The classes handle cookies, session state, etc and you can parse the NSData that comes out.
http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html
Below's an example of hitting a URL and getting the response as a NSString:
NSURL *URL=[[NSURL alloc] initWithString:stringForURL];
NSString *results = [[NSString alloc] initWithContentsOfURL :URL];
The iPhone can consume web services quite easily. NSURLRequest is often the starting point. Since you are new to iPhone development, it may be the easiest path without getting into local sql storage.
At a recent event Open Data was presented as a new and growing data source. The general idea is governments, provinces/states, municipalities/counties are opening up their vast amounts of data like transit schedules or trash pickup times so that people can build applications off of them. Vancouver has done this and some great apps have been produced. This is a useful start to looking for data.
Otherwise, just use the StackOverflow RSS feed; lots of data, constantly being updated.
After you've chosen your data source, NSURLConnection or NSString allows you to query that data from the iPhone
精彩评论