开发者

How to convert a html page into a native iPhone view?

开发者 https://www.devze.com 2023-03-20 21:16 出处:网络
I would like to replicate the Stackoverflo开发者_如何转开发w \"Ask Question\" page, to be run natively on the iPhone. The view contains two text boxes (a title and a text section) and a submit button.

I would like to replicate the Stackoverflo开发者_如何转开发w "Ask Question" page, to be run natively on the iPhone. The view contains two text boxes (a title and a text section) and a submit button.

When I press the submit button, how do I send the contents of the view to Stackoverflow?

What relevant iOS classes do I need to use?

Is it possible to do this without any APIs? I want a generic solution for any website.


You can do something like this:

NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com/questions/ask/submit"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSString *body = [NSStringstringWithFormat:@"title=%@&post-text=%@", title, question]; 
NSData *requestBody = [body dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:requestBody];

NSURLResponse *response = NULL;
NSError *requestError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease];


White woking with StackOverflow in particular in a native iPhone app you'll have to use API:

https://stackapps.com/questions/1/api-documentation-and-help

0

精彩评论

暂无评论...
验证码 换一张
取 消