开发者

iOS Programming with Web database interface

I am programming in Obj-C with X-code and I want to create a project where I am able to pull up information from the database that I have created in my website.

I understand that this can be safely and easily done with a mobile web application. Any i开发者_运维知识库deas how on how I parse the database with Objective-C and X-code ?

Please reply.

Thanks and regards, -Venkat


If i'm not mistaken the iOS SDK can not connect directly to your database. The way I do this is to send out a post request using the ASIHTTP class and then parse the returned data from your website. Read the documentation here. This is an example of how to use it from one of my own applications:

NSURL *url = [NSURL URLWithString:@"yoursite.com/page.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:variable1 forKey:@"key1"];
[request setPostValue:variable2 forKey:@"key2"];
[request setPostValue:variable3 forKey:@"key3"];
[request setDelegate:self];

[request startAsynchronous];

You then catch the result with the following code:

- (void)requestFinished:(ASIHTTPRequest *)request {
    NSError *error = [request error];
if (!error) {
    NSString *response = [request responseString];
    //do your parsing here
}
}

Don't forget to include the required files and classes to your app. But it's all explained in the documentation.

Hope it helps a bit!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜