How to read / write data to a web server in an iPhone app
I am working on an iphone application which would be able to retrieve/publish information from/to a web server. I want to use out-of-the-box technology on the server side and as much built-in iphone capabilities as possible. Here are my thoughts so far:
I initially thought about using rss feeds: Writing an rss reader i开发者_如何学运维s quite straightforward. However I do not seem able to find information regarding the publishing of an rss article from the iphone. Does anyone have a smart idea on this point?
I then thought of setting up dedicated email accounts (once again it's a prototype app). Sending then becomes easy via the iphone. Receiving emails from within a custom iphone ap however seems pretty involved. Once again: any smart thought on this?
There are probably other ways of doing what I want which elude me. Any constructive suggestions would be very much appreciated.
I would guess it depends on how much data you want to push back to your server. If its just a few items I would sent a request to a php page on your server and have it update a database with the info. You can use GET or POST. Not sure what the limits are but we do this with our app to get data on what movie the user has requested, the UUID and other useful data.
For example:
NSString * uId = [[UIDevice currentDevice] uniqueIdentifier];
NSString * episodeString = [URLString substringFromIndex:73]; //strip out the stuff before the enclosing folder
NSArray * episodeArray = [episodeString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
NSString * resVersion = episodeArray.lastObject; // get either small.mov, medium.mov or large.mov
NSString * episode = [episodeArray objectAtIndex:0];// get the enclosing folder
NSMutableURLRequest *statsRequest = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:kAppStats]] autorelease];
[statsRequest setHTTPMethod:@"POST"];
NSString *requestBody = [NSString
stringWithFormat:@"episode=%@&res=%@&uuid=%@",
[episode stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[resVersion stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[uId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
];
[statsRequest setHTTPBody:[requestBody dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *statsConnection = [[NSURLConnection alloc] initWithRequest:statsRequest delegate:self];
[statsConnection start];
[statsConnection release];
This is sent to a php script that gets the data through standard POST and updates a MySQL database. Don't see why you couldn't do something similar.
It is difficult to tell precisely whether the built-in capabilities of the iOS API will do exactly what you want, however what you have described sounds like it could be accomplished quite readily by creating a Safari (browser) application, rather than worrying about custom iPhone development.
RSS feeds are typically managed on the server and consumed by the client. I can't tell from your description how the emails are involved, but again if you are processing your feeds and emails on the server, a browser based application will have everything it needs.
精彩评论